Skip to content

Commit

Permalink
updates chains; cleanup readme
Browse files Browse the repository at this point in the history
  • Loading branch information
clbrge committed Aug 28, 2022
1 parent a2916a5 commit 06b4936
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 10 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions examples/svelte-vite-template-web3/src/Contracts.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script>
import { defaultEvmStores as evm, connected, chainId, chainData, contracts } from 'svelte-web3'
import IERC20 from '@openzeppelin/contracts/build/contracts/IERC20.json'
const LINKTOKEN_ADDRESS_ON_GOERLI = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'
evm.attachContract('link', LINKTOKEN_ADDRESS_ON_GOERLI, IERC20.abi)
</script>


<div class="content">

<h1>svelte-web3</h1>

<h2>using the '$contracts' store</h2>


<p>
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
</p>

<pre><code>
const LINKTOKEN_ADDRESS_ON_GOERLI = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'

evm.attachContract('link', LINKTOKEN_ADDRESS_ON_GOERLI, IERC20.abi)
</code></pre>


{#if $connected }

{#if $chainId !== 5 }

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

{:else if $contracts.link}

{#await $contracts.link.methods.totalSupply().call() }
<span>waiting for $contracts.link.methods.totalSupply().call() Promise...</span>
{:then supply}
<p>We have the result of $contracts.link.methods.totalSupply().call() :</p>
<p>ERC20 LINK contract has a supply of {supply} tokens on Görli.</p>
{/await}

{/if}

{:else}

<p>
Please first <a href="/setproviders">connect</a>
connect to the görli network to be able to use this page.
</p>

{/if}

{#if false}
<button class="button" on:click={exec}>Send 0.01 Gorli ETH to the zero address</button>
{/if}

</div>
18 changes: 18 additions & 0 deletions examples/svelte-vite-template-web3/src/Menu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
</script>

<hr />

<div class="menu">
<a href="/">Home</a>

<a href="/setprovider">setProvider()</a>

<a href="/contracts">$contracts </a>
</div>

<style global>
</style>
47 changes: 37 additions & 10 deletions src/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 06b4936

Please sign in to comment.