web3.js as a Svelte store.
npm i svelte-web3
Import the ethereum
main helper and needed derived Svelte stores (see list below):
import { ethereum, web3, selectedAccount, isListening } from 'svelte-ethereum';
To enable connection to the current window provider:
ethereum.setBrowserProvider()
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>)
- chainId: The current blokchain Id.
- chainName: Name of the The current blokchain.
- isListening: true if connection to the provider was successful.
- selectedAccount: current selected account.
Svelte stores are automatically updated when network or selected account change.
Please see the file example/App.svelte
for more usage information.
npm run example