0.3.1 • Published 2 years ago

@sw3/providers v0.3.1

Weekly downloads
-
License
AGPLv3
Repository
-
Last release
2 years ago

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

MethodDescription
✅ eth_requestAccountsEthereum JSON-RPC compatible
✅ eth_accountsEthereum JSON-RPC compatible
✅ eth_disconnectEthereum JSON-RPC compatible
❌ personal_signEthereum JSON-RPC compatible
❌ eth_signEthereum JSON-RPC compatible
❌ eth_signTypedData_v4Ethereum JSON-RPC compatible
❌ personal_unlockAccountEthereum JSON-RPC compatible
✅ sw3_signSW3 singer
EventsDescription
✅ accountsChangedMetaMask compatible
✅ disconnectMetaMask compatible
✅ connectMetaMask compatible
✅ sw3_noLoginSW3 Event