0.1.2 • Published 2 years ago
@szys/sw3 v0.1.2
Silvia Web 3
A Web based crypto wallet to connect Silvia Blockchain apps.
You can use it to connect to the Silvia.link blockchain network and sign transactions without a private key.
Usage
import { WebSocketProvider, JsonRpcProvider } from '@szys/sw3'
import { Contract } from '@ethersproject/contracts'
// Provider
const provider = new WebSocketProvider('wss://rpc.beta.silvia.link/ws')
// Signer
const account = await provider.send('eth_requestAccounts')
const contract = new Contract(contractAddress, abi, provider.getSigner(account))
Account Caching
If you're using a reactive framework like vue/react, you can maintain the state by yourself:
const provider = new WebSocketProvider('wss://rpc.beta.silvia.link/ws')
const state = { account: provider.account }
provider.SW3.on('accountsChanged', () => {
state.account = provider.account
})
By default, SW3 caches account address using sessionStorage (provider.SW3.account
) in convenience, you can disable it by changing the option setting to {cache: false}
. eg:
const provider = new WebSocketProvider('wss://rpc.beta.silvia.link/ws', null, { cache: false })
Provider API
Method | Description |
---|---|
✅ eth_requestAccounts | Ethereum JSON-RPC compatible |
✅ eth_accounts | Ethereum JSON-RPC compatible |
✅ eth_disconnect | Ethereum JSON-RPC compatible |
❌ personal_sign | Ethereum JSON-RPC compatible |
❌ eth_sign | Ethereum JSON-RPC compatible |
❌ eth_signTypedData_v4 | Ethereum JSON-RPC compatible |
❌ personal_unlockAccount | Ethereum JSON-RPC compatible |
✅ sw3_sign | SW3 singer |
Events | Description |
---|---|
✅ accountsChanged | MetaMask compatible |
✅ disconnect | MetaMask compatible |
✅ connect | MetaMask compatible |
✅ sw3_noLogin | SW3 Event |