Skip to content

Commit bce5c7a

Browse files
committed
updates chains+ example contract store
1 parent 33bedfe commit bce5c7a

File tree

5 files changed

+244
-75
lines changed

5 files changed

+244
-75
lines changed

examples/svelte-app-template-web3/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
"start": "sirv public"
99
},
1010
"devDependencies": {
11-
"svelte-web3": "file:../../",
1211
"@rollup/plugin-commonjs": "^21.0.1",
1312
"@rollup/plugin-node-resolve": "^13.1.1",
1413
"rollup": "^2.61.1",
1514
"rollup-plugin-css-only": "^3.1.0",
1615
"rollup-plugin-livereload": "^2.0.5",
1716
"rollup-plugin-svelte": "^7.0.0",
1817
"rollup-plugin-terser": "^7.0.0",
19-
"svelte": "^3.44.3"
18+
"svelte": "^3.44.3",
19+
"svelte-web3": "file:../../"
2020
},
2121
"dependencies": {
22+
"@openzeppelin/contracts": "^4.4.1",
23+
"@rollup/plugin-json": "^4.1.0",
2224
"sirv-cli": "^1.0.14"
2325
}
2426
}

examples/svelte-app-template-web3/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import svelte from 'rollup-plugin-svelte';
22
import commonjs from '@rollup/plugin-commonjs';
3+
import json from '@rollup/plugin-json';
34
import resolve from '@rollup/plugin-node-resolve';
45
import livereload from 'rollup-plugin-livereload';
56
import { terser } from 'rollup-plugin-terser';
@@ -50,7 +51,7 @@ export default {
5051
// we'll extract any component CSS out into
5152
// a separate file - better for performance
5253
css({ output: 'bundle.css' }),
53-
54+
json(),
5455
// If you have external dependencies installed from
5556
// npm, you'll most likely need these plugins. In
5657
// some cases you'll need additional configuration -

examples/svelte-app-template-web3/src/MonoChain.svelte

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
chainId,
1010
chainData } from 'svelte-web3'
1111
12+
import DAI from './contract-stores.js'
13+
1214
import { Balance } from 'svelte-web3/components'
1315
1416
let tipAddress = '0x834356a88C66897FA0A05a61964a91A607956ee3'
@@ -54,10 +56,16 @@
5456
}
5557
5658
const disconnect = async () => {
59+
60+
console.log( await $DAI.methods.totalSupply().call() )
61+
5762
await defaultEvmStores.disconnect()
5863
pending = false
5964
}
6065
66+
67+
$: DAISupply = $DAI ? $DAI.methods.totalSupply().call() : ''
68+
6169
</script>
6270

6371
<p class="subtitle">
@@ -100,4 +108,11 @@
100108
<p><button class="button is-primary is-light" on:click="{sendTip}">send 0.01 {$chainData.nativeCurrency?.symbol} tip to {tipAddress} (author)</button></p>
101109
{/if}
102110

111+
{#await DAISupply}
112+
pending contract definition
113+
{:then value}
114+
{value}
115+
{/await}
116+
117+
103118
{/if}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import ERC20 from '@openzeppelin/contracts/build/contracts/IERC20.json'
3+
4+
import { derived } from 'svelte/store'
5+
import { web3, chainId } from 'svelte-web3'
6+
7+
const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f'
8+
9+
const myContractStore = derived([web3, chainId], ([$web3, $chainId]) => {
10+
if ($chainId && $web3.eth) {
11+
// DO whaever nececessay to get address from chainId
12+
console.log('chainId is', $chainId)
13+
return new $web3.eth.Contract(ERC20.abi, DAI, {})
14+
}
15+
return null
16+
})
17+
18+
export default myContractStore

0 commit comments

Comments
 (0)