@sei-js/create-sei 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +16 -25
- package/biome.json +8 -0
- package/dist/main.js +12 -11
- package/dist/templates/next-cosmos-template/.eslintrc.json +1 -1
- package/dist/templates/next-cosmos-template/next.config.mjs +9 -9
- package/dist/templates/next-cosmos-template/package.json +29 -29
- package/dist/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +162 -171
- package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +92 -94
- package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +22 -49
- package/dist/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
- package/dist/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +13 -17
- package/dist/templates/next-cosmos-template/src/app/components/index.ts +3 -3
- package/dist/templates/next-cosmos-template/src/app/constants/chain.ts +9 -9
- package/dist/templates/next-cosmos-template/src/app/constants/index.ts +1 -1
- package/dist/templates/next-cosmos-template/src/app/index.css +99 -86
- package/dist/templates/next-cosmos-template/src/app/layout.tsx +12 -12
- package/dist/templates/next-cosmos-template/src/app/page.tsx +13 -13
- package/dist/templates/next-cosmos-template/tsconfig.json +24 -24
- package/dist/templates/next-wagmi-template/.eslintrc.json +1 -1
- package/dist/templates/next-wagmi-template/package.json +28 -28
- package/dist/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +223 -237
- package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +92 -94
- package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +10 -36
- package/dist/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +29 -28
- package/dist/templates/next-wagmi-template/src/app/components/index.ts +2 -2
- package/dist/templates/next-wagmi-template/src/app/constants/chain.ts +2 -2
- package/dist/templates/next-wagmi-template/src/app/constants/index.ts +1 -1
- package/dist/templates/next-wagmi-template/src/app/index.css +99 -86
- package/dist/templates/next-wagmi-template/src/app/layout.tsx +12 -12
- package/dist/templates/next-wagmi-template/src/app/page.tsx +17 -17
- package/dist/templates/next-wagmi-template/tsconfig.json +24 -24
- package/dist/templates/vite-cosmos-template/.eslintrc.cjs +10 -17
- package/dist/templates/vite-cosmos-template/package.json +33 -33
- package/dist/templates/vite-cosmos-template/src/App.tsx +11 -12
- package/dist/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +162 -171
- package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +92 -94
- package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +20 -45
- package/dist/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
- package/dist/templates/vite-cosmos-template/src/components/Web3Provider.tsx +14 -18
- package/dist/templates/vite-cosmos-template/src/components/index.ts +4 -4
- package/dist/templates/vite-cosmos-template/src/constants/chain.ts +9 -9
- package/dist/templates/vite-cosmos-template/src/constants/index.ts +1 -1
- package/dist/templates/vite-cosmos-template/src/index.css +99 -86
- package/dist/templates/vite-cosmos-template/src/main.tsx +10 -10
- package/dist/templates/vite-cosmos-template/tsconfig.app.json +21 -23
- package/dist/templates/vite-cosmos-template/tsconfig.json +9 -9
- package/dist/templates/vite-cosmos-template/tsconfig.node.json +11 -11
- package/dist/templates/vite-cosmos-template/vite.config.ts +4 -4
- package/dist/templates/vite-wagmi-template/.eslintrc.cjs +10 -17
- package/dist/templates/vite-wagmi-template/package.json +31 -31
- package/dist/templates/vite-wagmi-template/src/App.tsx +12 -13
- package/dist/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +225 -239
- package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +92 -94
- package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +28 -53
- package/dist/templates/vite-wagmi-template/src/components/Web3Provider.tsx +29 -28
- package/dist/templates/vite-wagmi-template/src/constants/chain.ts +1 -1
- package/dist/templates/vite-wagmi-template/src/constants/index.ts +1 -1
- package/dist/templates/vite-wagmi-template/src/index.css +98 -85
- package/dist/templates/vite-wagmi-template/src/main.tsx +10 -10
- package/dist/templates/vite-wagmi-template/tsconfig.app.json +21 -23
- package/dist/templates/vite-wagmi-template/tsconfig.json +9 -9
- package/dist/templates/vite-wagmi-template/tsconfig.node.json +11 -11
- package/dist/templates/vite-wagmi-template/vite.config.ts +7 -7
- package/package.json +3 -2
- package/src/main.ts +31 -33
- package/templates/next-cosmos-template/.eslintrc.json +1 -1
- package/templates/next-cosmos-template/next.config.mjs +9 -9
- package/templates/next-cosmos-template/package.json +29 -29
- package/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +162 -171
- package/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +92 -94
- package/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +22 -49
- package/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
- package/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +13 -17
- package/templates/next-cosmos-template/src/app/components/index.ts +3 -3
- package/templates/next-cosmos-template/src/app/constants/chain.ts +9 -9
- package/templates/next-cosmos-template/src/app/constants/index.ts +1 -1
- package/templates/next-cosmos-template/src/app/index.css +99 -86
- package/templates/next-cosmos-template/src/app/layout.tsx +12 -12
- package/templates/next-cosmos-template/src/app/page.tsx +13 -13
- package/templates/next-cosmos-template/tsconfig.json +24 -24
- package/templates/next-wagmi-template/.eslintrc.json +1 -1
- package/templates/next-wagmi-template/package.json +28 -28
- package/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +223 -237
- package/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +92 -94
- package/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +10 -36
- package/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +29 -28
- package/templates/next-wagmi-template/src/app/components/index.ts +2 -2
- package/templates/next-wagmi-template/src/app/constants/chain.ts +2 -2
- package/templates/next-wagmi-template/src/app/constants/index.ts +1 -1
- package/templates/next-wagmi-template/src/app/index.css +99 -86
- package/templates/next-wagmi-template/src/app/layout.tsx +12 -12
- package/templates/next-wagmi-template/src/app/page.tsx +17 -17
- package/templates/next-wagmi-template/tsconfig.json +24 -24
- package/templates/vite-cosmos-template/.eslintrc.cjs +10 -17
- package/templates/vite-cosmos-template/package.json +33 -33
- package/templates/vite-cosmos-template/src/App.tsx +11 -12
- package/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +162 -171
- package/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +92 -94
- package/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +20 -45
- package/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
- package/templates/vite-cosmos-template/src/components/Web3Provider.tsx +14 -18
- package/templates/vite-cosmos-template/src/components/index.ts +4 -4
- package/templates/vite-cosmos-template/src/constants/chain.ts +9 -9
- package/templates/vite-cosmos-template/src/constants/index.ts +1 -1
- package/templates/vite-cosmos-template/src/index.css +99 -86
- package/templates/vite-cosmos-template/src/main.tsx +10 -10
- package/templates/vite-cosmos-template/tsconfig.app.json +21 -23
- package/templates/vite-cosmos-template/tsconfig.json +9 -9
- package/templates/vite-cosmos-template/tsconfig.node.json +11 -11
- package/templates/vite-cosmos-template/vite.config.ts +4 -4
- package/templates/vite-wagmi-template/.eslintrc.cjs +10 -17
- package/templates/vite-wagmi-template/package.json +31 -31
- package/templates/vite-wagmi-template/src/App.tsx +12 -13
- package/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +225 -239
- package/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +92 -94
- package/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +28 -53
- package/templates/vite-wagmi-template/src/components/Web3Provider.tsx +29 -28
- package/templates/vite-wagmi-template/src/constants/chain.ts +1 -1
- package/templates/vite-wagmi-template/src/constants/index.ts +1 -1
- package/templates/vite-wagmi-template/src/index.css +98 -85
- package/templates/vite-wagmi-template/src/main.tsx +10 -10
- package/templates/vite-wagmi-template/tsconfig.app.json +21 -23
- package/templates/vite-wagmi-template/tsconfig.json +9 -9
- package/templates/vite-wagmi-template/tsconfig.node.json +11 -11
- package/templates/vite-wagmi-template/vite.config.ts +7 -7
- package/tsconfig.json +24 -28
|
@@ -1,271 +1,257 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { BANK_PRECOMPILE_ABI, BANK_PRECOMPILE_ADDRESS, WASM_PRECOMPILE_ABI, WASM_PRECOMPILE_ADDRESS } from
|
|
4
|
-
import { useState } from
|
|
5
|
-
import { ReadContractParameters, formatEther, fromHex, parseEther, toHex } from
|
|
6
|
-
import { useAccount, usePublicClient, useWriteContract } from
|
|
3
|
+
import { BANK_PRECOMPILE_ABI, BANK_PRECOMPILE_ADDRESS, WASM_PRECOMPILE_ABI, WASM_PRECOMPILE_ADDRESS } from '@sei-js/evm';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { ReadContractParameters, formatEther, fromHex, parseEther, toHex } from 'viem';
|
|
6
|
+
import { useAccount, usePublicClient, useWriteContract } from 'wagmi';
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import './Homepage.css';
|
|
9
9
|
|
|
10
10
|
function Examples() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const [balance, setBalance] = useState('');
|
|
12
|
+
const [supply, setSupply] = useState('');
|
|
13
|
+
const [count, setCount] = useState(0);
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const publicClient = usePublicClient();
|
|
16
|
+
const { address } = useAccount();
|
|
17
17
|
const { writeContractAsync } = useWriteContract();
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const formatLargeSeiNumber = (num: string, decimals: number): string => {
|
|
20
20
|
if (num.length > 10) {
|
|
21
|
-
return (
|
|
21
|
+
return (
|
|
22
|
+
(Number(num) / 1000000 / 1000000000).toLocaleString(navigator.language, { minimumFractionDigits: decimals, maximumFractionDigits: decimals }) + ' B'
|
|
23
|
+
);
|
|
22
24
|
} else {
|
|
23
25
|
return (Number(num) / 1000000).toLocaleString(navigator.language);
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const copyToClipboard = (text: string) => {
|
|
30
|
+
try {
|
|
31
|
+
navigator.clipboard.writeText(text);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error('Failed to copy text: ', err);
|
|
34
|
+
} finally {
|
|
35
|
+
alert('Copied to clipboard!');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const renderAddressExample = () => {
|
|
40
|
+
return (
|
|
41
|
+
<div className="card">
|
|
42
|
+
<div className="card-header">
|
|
43
|
+
<p className="card__title">Wallet address</p>
|
|
44
|
+
<small className="card__description">
|
|
45
|
+
<a href="https://viem.sh/docs/clients/public.html" target="_blank">
|
|
46
|
+
Viem Public Client
|
|
47
|
+
</a>{' '}
|
|
48
|
+
query example
|
|
49
|
+
</small>
|
|
50
|
+
</div>
|
|
51
|
+
<div className="card-body">
|
|
52
|
+
<div className="content-background space-between">
|
|
53
|
+
{address ? (
|
|
54
|
+
<div>
|
|
55
|
+
<p className="card-footer">{address}</p>
|
|
56
|
+
</div>
|
|
57
|
+
) : (
|
|
58
|
+
<p> --- </p>
|
|
59
|
+
)}
|
|
60
|
+
|
|
61
|
+
<button className="small outline" onClick={() => copyToClipboard(address as string)}>
|
|
62
|
+
Copy
|
|
63
|
+
</button>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
<div className="card-footer"></div>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getBalanceWagmi = async () => {
|
|
72
|
+
if (!address || !publicClient) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
const weiBalance = await publicClient.getBalance({ address });
|
|
76
|
+
const seiBalance = formatEther(weiBalance);
|
|
77
|
+
setBalance(seiBalance);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const renderBalanceExample = () => {
|
|
81
|
+
return (
|
|
82
|
+
<div className="card">
|
|
83
|
+
<div className="card-header">
|
|
84
|
+
<p className="card__title">Wallet balance</p>
|
|
85
|
+
<small className="card__description">
|
|
86
|
+
<a href="https://viem.sh/docs/clients/public.html" target="_blank">
|
|
87
|
+
Viem Public Client
|
|
88
|
+
</a>{' '}
|
|
89
|
+
query example
|
|
90
|
+
</small>
|
|
91
|
+
</div>
|
|
92
|
+
<div className="card-body">
|
|
93
|
+
<div className="content-background space-between">
|
|
94
|
+
<small>SEI</small>
|
|
95
|
+
<p>{balance ? balance : '---'} SEI</p>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
<div className="card-footer">
|
|
99
|
+
<button onClick={getBalanceWagmi}>Fetch balance</button>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Example of using precompiles to query native Sei modules.
|
|
106
|
+
const getBankSupply = async () => {
|
|
107
|
+
if (!publicClient) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
36
110
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
address ?
|
|
52
|
-
<div>
|
|
53
|
-
<p className="card-footer">
|
|
54
|
-
{address}
|
|
55
|
-
</p>
|
|
56
|
-
</div> :
|
|
57
|
-
<p> --- </p>
|
|
58
|
-
}
|
|
111
|
+
const params: ReadContractParameters = {
|
|
112
|
+
address: BANK_PRECOMPILE_ADDRESS,
|
|
113
|
+
abi: BANK_PRECOMPILE_ABI,
|
|
114
|
+
functionName: 'supply',
|
|
115
|
+
args: ['usei']
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
const response = (await publicClient.readContract(params)) as BigInt;
|
|
119
|
+
const supply = formatLargeSeiNumber(response.toString(), 1);
|
|
120
|
+
setSupply(supply);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.log(e);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
59
125
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
126
|
+
const renderBankSupplyExample = () => {
|
|
127
|
+
return (
|
|
128
|
+
<div className="card">
|
|
129
|
+
<div className="card-header">
|
|
130
|
+
<p className="card__title">Total Sei supply</p>
|
|
131
|
+
<small className="card__description">
|
|
132
|
+
<a href="https://www.docs.sei.io/dev-interoperability/precompiles/bank" target="_blank">
|
|
133
|
+
{' '}
|
|
134
|
+
Bank precompile
|
|
135
|
+
</a>{' '}
|
|
136
|
+
example for querying native Sei modules
|
|
137
|
+
</small>
|
|
138
|
+
</div>
|
|
139
|
+
<div className="card-body">
|
|
140
|
+
<div className="content-background space-between">
|
|
141
|
+
<small>SEI</small>
|
|
142
|
+
<p>{supply}</p>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
<div className="card-footer">
|
|
146
|
+
<button onClick={getBankSupply}>Fetch supply</button>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
77
151
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const seiBalance = formatEther(weiBalance)
|
|
84
|
-
setBalance(seiBalance);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const renderBalanceExample = () => {
|
|
88
|
-
return (
|
|
89
|
-
<div className="card">
|
|
90
|
-
<div className="card-header">
|
|
91
|
-
<p className="card__title">Wallet balance</p>
|
|
92
|
-
<small className="card__description">
|
|
93
|
-
<a
|
|
94
|
-
href="https://viem.sh/docs/clients/public.html"
|
|
95
|
-
target="_blank">Viem Public Client</a> query example
|
|
96
|
-
</small>
|
|
97
|
-
</div>
|
|
98
|
-
<div className="card-body">
|
|
99
|
-
<div className="content-background space-between">
|
|
100
|
-
<small>SEI</small>
|
|
101
|
-
<p>{balance ? balance : '---' } SEI</p>
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
<div className="card-footer">
|
|
105
|
-
<button onClick={getBalanceWagmi}>Fetch balance</button>
|
|
106
|
-
</div>
|
|
107
|
-
</div>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Example of using precompiles to query native Sei modules.
|
|
112
|
-
const getBankSupply = async () => {
|
|
113
|
-
if (!publicClient) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
152
|
+
// Fetch count of a CosmWasm Contract using WASM Precompile
|
|
153
|
+
const fetchCount = async () => {
|
|
154
|
+
if (!publicClient) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
116
157
|
|
|
117
|
-
|
|
118
|
-
address: BANK_PRECOMPILE_ADDRESS,
|
|
119
|
-
abi: BANK_PRECOMPILE_ABI,
|
|
120
|
-
functionName: 'supply',
|
|
121
|
-
args: ['usei']
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
const response = await publicClient.readContract(params) as BigInt;
|
|
125
|
-
const supply = formatLargeSeiNumber(response.toString(), 1)
|
|
126
|
-
setSupply(supply);
|
|
127
|
-
} catch (e) {
|
|
128
|
-
console.log(e);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const renderBankSupplyExample = () => {
|
|
133
|
-
return (
|
|
134
|
-
<div className="card">
|
|
135
|
-
<div className="card-header">
|
|
136
|
-
<p className="card__title">Total Sei supply</p>
|
|
137
|
-
<small className="card__description">
|
|
138
|
-
<a
|
|
139
|
-
href="https://www.docs.sei.io/dev-interoperability/precompiles/bank"
|
|
140
|
-
target="_blank"> Bank precompile
|
|
141
|
-
</a> example for querying native Sei
|
|
142
|
-
modules
|
|
143
|
-
</small>
|
|
144
|
-
</div>
|
|
145
|
-
<div className="card-body">
|
|
146
|
-
<div className="content-background space-between">
|
|
147
|
-
<small>SEI</small>
|
|
148
|
-
<p>{supply}</p>
|
|
149
|
-
</div>
|
|
150
|
-
</div>
|
|
151
|
-
<div className="card-footer">
|
|
152
|
-
<button onClick={getBankSupply}>Fetch supply</button>
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
)
|
|
156
|
-
}
|
|
158
|
+
const COUNTER_CONTRACT_ADDRESS = 'sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m';
|
|
157
159
|
|
|
158
|
-
|
|
159
|
-
const fetchCount = async () => {
|
|
160
|
-
if (!publicClient) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
160
|
+
const queryMsg = toHex(JSON.stringify({ get_count: {} }));
|
|
163
161
|
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
const params: ReadContractParameters = {
|
|
163
|
+
address: WASM_PRECOMPILE_ADDRESS,
|
|
164
|
+
abi: WASM_PRECOMPILE_ABI,
|
|
165
|
+
functionName: 'query',
|
|
166
|
+
args: [COUNTER_CONTRACT_ADDRESS, queryMsg]
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
const response = (await publicClient?.readContract(params)) as `0x${string}`;
|
|
170
|
+
const { count } = JSON.parse(fromHex(response, 'string'));
|
|
171
|
+
setCount(count);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
console.log(e);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
166
176
|
|
|
167
|
-
|
|
177
|
+
// Fetch count of a CosmWasm Contract using WASM Precompile
|
|
178
|
+
const incrementCounter = async () => {
|
|
179
|
+
if (!address || !publicClient) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
168
182
|
|
|
169
|
-
|
|
170
|
-
address: WASM_PRECOMPILE_ADDRESS,
|
|
171
|
-
abi: WASM_PRECOMPILE_ABI,
|
|
172
|
-
functionName: 'query',
|
|
173
|
-
args: [COUNTER_CONTRACT_ADDRESS, queryMsg]
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
const response = await publicClient?.readContract(params) as `0x${string}`;
|
|
177
|
-
const { count } = JSON.parse(fromHex(response, 'string'));
|
|
178
|
-
setCount(count);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
console.log(e);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
+
const COUNTER_CONTRACT_ADDRESS = 'sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m';
|
|
183
184
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const coins = toHex('[]')
|
|
195
|
-
const params = {
|
|
196
|
-
account: address,
|
|
197
|
-
address: WASM_PRECOMPILE_ADDRESS,
|
|
198
|
-
abi: WASM_PRECOMPILE_ABI,
|
|
199
|
-
functionName: 'execute',
|
|
200
|
-
args: [COUNTER_CONTRACT_ADDRESS, execMsg, coins],
|
|
201
|
-
value: parseEther('0')
|
|
202
|
-
}
|
|
185
|
+
const execMsg = toHex(JSON.stringify({ increment: {} }));
|
|
186
|
+
const coins = toHex('[]');
|
|
187
|
+
const params = {
|
|
188
|
+
account: address,
|
|
189
|
+
address: WASM_PRECOMPILE_ADDRESS,
|
|
190
|
+
abi: WASM_PRECOMPILE_ABI,
|
|
191
|
+
functionName: 'execute',
|
|
192
|
+
args: [COUNTER_CONTRACT_ADDRESS, execMsg, coins],
|
|
193
|
+
value: parseEther('0')
|
|
194
|
+
};
|
|
203
195
|
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
try {
|
|
197
|
+
const estimatedGas = await publicClient.estimateContractGas(params);
|
|
206
198
|
|
|
207
|
-
|
|
208
|
-
|
|
199
|
+
// Call smart contract execute msg
|
|
200
|
+
await writeContractAsync({ ...params, gas: estimatedGas });
|
|
209
201
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
202
|
+
// Wait for 1 block to confirm transaction
|
|
203
|
+
setTimeout(() => {}, 400);
|
|
204
|
+
await fetchCount();
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.log(error);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
213
209
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
const renderCounterContractExample = () => {
|
|
211
|
+
return (
|
|
212
|
+
<div className="card">
|
|
213
|
+
<div className="card-header">
|
|
214
|
+
<p className="card__title">Smart contract interaction</p>
|
|
215
|
+
<small>
|
|
216
|
+
<a href="https://www.docs.sei.io/dev-interoperability/precompiles/cosmwasm" target="_blank">
|
|
217
|
+
WASM Precompile
|
|
218
|
+
</a>{' '}
|
|
219
|
+
example of CosmWasm smart contract interaction
|
|
220
|
+
</small>
|
|
221
|
+
</div>
|
|
222
|
+
<div className="card-body">
|
|
223
|
+
<div className="content-background space-between">
|
|
224
|
+
<small>Count</small>
|
|
225
|
+
<p>{count}</p>
|
|
226
|
+
<button className="small outline" onClick={incrementCounter}>
|
|
227
|
+
Increase
|
|
228
|
+
</button>
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
<div className="card-footer">
|
|
232
|
+
<button onClick={fetchCount}>Fetch count</button>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
};
|
|
218
237
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
<small>
|
|
225
|
-
<a
|
|
226
|
-
href="https://www.docs.sei.io/dev-interoperability/precompiles/cosmwasm"
|
|
227
|
-
target="_blank">
|
|
228
|
-
WASM Precompile
|
|
229
|
-
</a> example of CosmWasm smart
|
|
230
|
-
contract interaction
|
|
231
|
-
</small>
|
|
232
|
-
</div>
|
|
233
|
-
<div className="card-body">
|
|
234
|
-
<div className="content-background space-between">
|
|
235
|
-
<small>Count</small>
|
|
236
|
-
<p>{count}</p>
|
|
237
|
-
<button
|
|
238
|
-
className="small outline"
|
|
239
|
-
onClick={incrementCounter}
|
|
240
|
-
>
|
|
241
|
-
Increase
|
|
242
|
-
</button>
|
|
243
|
-
</div>
|
|
244
|
-
</div>
|
|
245
|
-
<div className="card-footer">
|
|
246
|
-
<button onClick={fetchCount}>Fetch count</button>
|
|
247
|
-
</div>
|
|
248
|
-
</div>
|
|
249
|
-
)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return (
|
|
253
|
-
<div className="container">
|
|
254
|
-
<div className="grid">
|
|
255
|
-
{/* First card */}
|
|
256
|
-
{renderAddressExample()}
|
|
238
|
+
return (
|
|
239
|
+
<div className="container">
|
|
240
|
+
<div className="grid">
|
|
241
|
+
{/* First card */}
|
|
242
|
+
{renderAddressExample()}
|
|
257
243
|
|
|
258
|
-
|
|
259
|
-
|
|
244
|
+
{/* Second card */}
|
|
245
|
+
{renderBalanceExample()}
|
|
260
246
|
|
|
261
|
-
|
|
262
|
-
|
|
247
|
+
{/* Third card */}
|
|
248
|
+
{renderBankSupplyExample()}
|
|
263
249
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
250
|
+
{/* Fourth card */}
|
|
251
|
+
{renderCounterContractExample()}
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
);
|
|
269
255
|
}
|
|
270
256
|
|
|
271
257
|
export default Examples;
|