@sw3/providers
v0.3.1
Published
Silvia Providers
Downloads
1
Readme
Silvia Web 3 Providers
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 '@sw3/providers'
import { Contract } from '@ethersproject/contracts'
// Provider
const provider = new WebSocketProvider('wss://rpc.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.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.silvia.link/ws', undefined, { 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 |