sapper-web3
v1.3.0
Published
web3.js as a Svelte store
Downloads
1
Readme
svelte-web3
web3.js 1.2.9 as a Svelte store.
Installation
npm i svelte-web3
Basic Usage
Import the ethStore
main connection helper and needed derived Svelte stores (see list below):
import { ethStore, web3, selectedAccount, connected } from 'svelte-web3';
To enable connection to the current window provider:
ethStore.setBrowserProvider()
To enable connection using an url string:
ethStore.setProvider('<ws/https or http provider url>')
If connection is successful, you can access the instantiated web3.js with the current window provider
using the $
svelte store syntax :
$web3.eth.getBalance(<Ethereum address>)
Derived stores
- connected: true if connection to the provider was successful.
- chainId: The current blokchain Id.
- chainName: Name of the The current blokchain.
- selectedAccount: current selected account.
- nativeCurrency: currency name in the current chain.
Svelte stores are automatically updated when network or the selected account change.
Please see the file example/App.svelte
for more usage information to start a transaction
and concrete usage of stores.
Demo/Example
npm run example