From 06b4936af9402a1a0b32b617a3dee25251fb88b6 Mon Sep 17 00:00:00 2001 From: Christophe Le Bars Date: Sun, 28 Aug 2022 22:14:47 +0200 Subject: [PATCH] updates chains; cleanup readme --- README.md | 22 +++++++ .../src/Contracts.svelte | 66 +++++++++++++++++++ .../svelte-vite-template-web3/src/Menu.svelte | 18 +++++ src/chains.js | 47 ++++++++++--- 4 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 examples/svelte-vite-template-web3/src/Contracts.svelte create mode 100644 examples/svelte-vite-template-web3/src/Menu.svelte diff --git a/README.md b/README.md index 03f829f..f54f340 100644 --- a/README.md +++ b/README.md @@ -435,7 +435,29 @@ generally depends on the type of provider you are using and a way to store connection information between page loads (for example by using localStorage). +### *X doesn't work after `await defaultEvmStores.setProvider()`* +It's not sufficient to `await` for the `setProvider` to be certain that +other derived stores have been populated. Instead you should subscribe +to the needed store and put your code inside the handler. + +For example: + +on + +```js +import { defaultEvmStores as evm, web3, selectedAccount } from 'svelte-web3' + +selectedAccount.subscribe(async $selectedAccount => { + if (!$selectedAccount) return + // do stuff here + // ... +}) + +onMount(() => { + evm.setProvider() +}) +``` ## Examples diff --git a/examples/svelte-vite-template-web3/src/Contracts.svelte b/examples/svelte-vite-template-web3/src/Contracts.svelte new file mode 100644 index 0000000..24546a4 --- /dev/null +++ b/examples/svelte-vite-template-web3/src/Contracts.svelte @@ -0,0 +1,66 @@ + + + +
+ +

svelte-web3

+ +

using the '$contracts' store

+ + +

+ The following code initialize the $contracts store with the ERC20 LINK Token. + Here we use the #await svelte block to load the token totalSupply of the contract +

+ +

+  const LINKTOKEN_ADDRESS_ON_GOERLI = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'
+
+  evm.attachContract('link', LINKTOKEN_ADDRESS_ON_GOERLI, IERC20.abi)
+  
+ + + {#if $connected } + + {#if $chainId !== 5 } + +

+ Your are connected to the wrong network ("{$chainData.name}")". Please + connect to the testnet Görli for the $contract store demo +

+ + {:else if $contracts.link} + + {#await $contracts.link.methods.totalSupply().call() } + waiting for $contracts.link.methods.totalSupply().call() Promise... + {:then supply} +

We have the result of $contracts.link.methods.totalSupply().call() :

+

ERC20 LINK contract has a supply of {supply} tokens on Görli.

+ {/await} + + {/if} + + {:else} + +

+ Please first connect + connect to the görli network to be able to use this page. +

+ + {/if} + + {#if false} + + {/if} + +
diff --git a/examples/svelte-vite-template-web3/src/Menu.svelte b/examples/svelte-vite-template-web3/src/Menu.svelte new file mode 100644 index 0000000..d03b4a4 --- /dev/null +++ b/examples/svelte-vite-template-web3/src/Menu.svelte @@ -0,0 +1,18 @@ + + +
+ + + + diff --git a/src/chains.js b/src/chains.js index 34d4c22..d13de7b 100644 --- a/src/chains.js +++ b/src/chains.js @@ -5495,22 +5495,23 @@ const chains = [ networkId: 8029 }, { - name: 'GeneChain Adenine Testnet', - chain: 'GeneChain', - rpc: [ 'https://rpc-testnet.genechain.io' ], - faucets: [ 'https://faucet.genechain.io' ], - nativeCurrency: { name: 'Testnet RNA', symbol: 'tRNA', decimals: 18 }, - infoURL: 'https://scan-testnet.genechain.io/', - shortName: 'GeneChainAdn', + name: 'Shardeum Liberty 1.3', + chain: 'Shardeum', + rpc: [ 'https://liberty10.shardeum.org/' ], + faucets: [ 'https://faucet.liberty10.shardeum.org' ], + nativeCurrency: { name: 'Shardeum SHM', symbol: 'SHM', decimals: 18 }, + infoURL: 'https://docs.shardeum.org/', + shortName: 'ShardeumSHM', chainId: 8080, networkId: 8080, explorers: [ { - name: 'GeneChain Adenine Testnet Scan', - url: 'https://scan-testnet.genechain.io', + name: 'Sharedum Scan', + url: 'https://explorer.liberty10.shardeum.org', standard: 'EIP3091' } - ] + ], + redFlags: [ 'reusedChainId' ] }, { name: 'Klaytn Mainnet Cypress', @@ -5542,6 +5543,32 @@ const chains = [ chainId: 8285, networkId: 8285 }, + { + name: 'Toki Network', + chain: 'TOKI', + rpc: [ 'https://mainnet.buildwithtoki.com/v0/rpc' ], + faucets: [], + nativeCurrency: { name: 'Toki', symbol: 'TOKI', decimals: 18 }, + infoURL: 'https://www.buildwithtoki.com', + shortName: 'toki', + chainId: 8654, + networkId: 8654, + icon: 'toki', + explorers: [] + }, + { + name: 'Toki Testnet', + chain: 'TOKI', + rpc: [ 'https://testnet.buildwithtoki.com/v0/rpc' ], + faucets: [], + nativeCurrency: { name: 'Toki', symbol: 'TOKI', decimals: 18 }, + infoURL: 'https://www.buildwithtoki.com', + shortName: 'toki-testnet', + chainId: 8655, + networkId: 8655, + icon: 'toki', + explorers: [] + }, { name: 'TOOL Global Mainnet', chain: 'OLO',