@sei-js/create-sei 0.0.1 → 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.
Files changed (155) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +16 -25
  4. package/biome.json +8 -0
  5. package/dist/main.js +162 -0
  6. package/dist/templates/next-cosmos-template/.eslintrc.json +3 -0
  7. package/dist/templates/next-cosmos-template/README.md +60 -0
  8. package/dist/templates/next-cosmos-template/next-env.d.ts +5 -0
  9. package/dist/templates/next-cosmos-template/next.config.mjs +14 -0
  10. package/dist/templates/next-cosmos-template/package.json +31 -0
  11. package/dist/templates/next-cosmos-template/public/next.svg +1 -0
  12. package/dist/templates/next-cosmos-template/public/sei-logotype.svg +15 -0
  13. package/dist/templates/next-cosmos-template/public/vercel.svg +1 -0
  14. package/dist/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +168 -0
  15. package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +154 -0
  16. package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +83 -0
  17. package/dist/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +18 -0
  18. package/dist/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +35 -0
  19. package/dist/templates/next-cosmos-template/src/app/components/index.ts +3 -0
  20. package/dist/templates/next-cosmos-template/src/app/constants/chain.ts +16 -0
  21. package/dist/templates/next-cosmos-template/src/app/constants/index.ts +1 -0
  22. package/dist/templates/next-cosmos-template/src/app/favicon.ico +0 -0
  23. package/dist/templates/next-cosmos-template/src/app/index.css +184 -0
  24. package/dist/templates/next-cosmos-template/src/app/layout.tsx +21 -0
  25. package/dist/templates/next-cosmos-template/src/app/page.tsx +17 -0
  26. package/dist/templates/next-cosmos-template/tsconfig.json +26 -0
  27. package/dist/templates/next-cosmos-template/yarn.lock +9814 -0
  28. package/dist/templates/next-wagmi-template/.eslintrc.json +3 -0
  29. package/dist/templates/next-wagmi-template/README.md +58 -0
  30. package/dist/templates/next-wagmi-template/next-env.d.ts +5 -0
  31. package/dist/templates/next-wagmi-template/next.config.mjs +4 -0
  32. package/dist/templates/next-wagmi-template/package.json +30 -0
  33. package/dist/templates/next-wagmi-template/public/sei-logotype.svg +15 -0
  34. package/dist/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +257 -0
  35. package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +154 -0
  36. package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +87 -0
  37. package/dist/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +74 -0
  38. package/dist/templates/next-wagmi-template/src/app/components/index.ts +2 -0
  39. package/dist/templates/next-wagmi-template/src/app/constants/chain.ts +7 -0
  40. package/dist/templates/next-wagmi-template/src/app/constants/index.ts +1 -0
  41. package/dist/templates/next-wagmi-template/src/app/favicon.ico +0 -0
  42. package/dist/templates/next-wagmi-template/src/app/index.css +184 -0
  43. package/dist/templates/next-wagmi-template/src/app/layout.tsx +21 -0
  44. package/dist/templates/next-wagmi-template/src/app/page.tsx +21 -0
  45. package/dist/templates/next-wagmi-template/tsconfig.json +26 -0
  46. package/dist/templates/next-wagmi-template/yarn.lock +4809 -0
  47. package/dist/templates/vite-cosmos-template/.eslintrc.cjs +11 -0
  48. package/dist/templates/vite-cosmos-template/README.md +72 -0
  49. package/dist/templates/vite-cosmos-template/favicon.ico +0 -0
  50. package/dist/templates/vite-cosmos-template/index.html +16 -0
  51. package/dist/templates/vite-cosmos-template/package.json +35 -0
  52. package/dist/templates/vite-cosmos-template/public/sei-logotype.svg +15 -0
  53. package/dist/templates/vite-cosmos-template/src/App.tsx +15 -0
  54. package/dist/templates/vite-cosmos-template/src/assets/react.svg +1 -0
  55. package/dist/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +168 -0
  56. package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +154 -0
  57. package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +77 -0
  58. package/dist/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +18 -0
  59. package/dist/templates/vite-cosmos-template/src/components/Web3Provider.tsx +41 -0
  60. package/dist/templates/vite-cosmos-template/src/components/index.ts +4 -0
  61. package/dist/templates/vite-cosmos-template/src/constants/chain.ts +16 -0
  62. package/dist/templates/vite-cosmos-template/src/constants/index.ts +1 -0
  63. package/dist/templates/vite-cosmos-template/src/index.css +184 -0
  64. package/dist/templates/vite-cosmos-template/src/main.tsx +12 -0
  65. package/dist/templates/vite-cosmos-template/src/vite-env.d.ts +1 -0
  66. package/dist/templates/vite-cosmos-template/tsconfig.app.json +25 -0
  67. package/dist/templates/vite-cosmos-template/tsconfig.json +11 -0
  68. package/dist/templates/vite-cosmos-template/tsconfig.node.json +14 -0
  69. package/dist/templates/vite-cosmos-template/vite.config.ts +7 -0
  70. package/dist/templates/vite-cosmos-template/yarn.lock +9323 -0
  71. package/dist/templates/vite-wagmi-template/.eslintrc.cjs +11 -0
  72. package/dist/templates/vite-wagmi-template/README.md +72 -0
  73. package/dist/templates/vite-wagmi-template/favicon.ico +0 -0
  74. package/dist/templates/vite-wagmi-template/index.html +12 -0
  75. package/dist/templates/vite-wagmi-template/package.json +33 -0
  76. package/dist/templates/vite-wagmi-template/public/sei-logotype.svg +15 -0
  77. package/dist/templates/vite-wagmi-template/src/App.tsx +21 -0
  78. package/dist/templates/vite-wagmi-template/src/assets/react.svg +1 -0
  79. package/dist/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +255 -0
  80. package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +154 -0
  81. package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +81 -0
  82. package/dist/templates/vite-wagmi-template/src/components/Web3Provider.tsx +72 -0
  83. package/dist/templates/vite-wagmi-template/src/constants/chain.ts +6 -0
  84. package/dist/templates/vite-wagmi-template/src/constants/index.ts +1 -0
  85. package/dist/templates/vite-wagmi-template/src/index.css +183 -0
  86. package/dist/templates/vite-wagmi-template/src/main.tsx +12 -0
  87. package/dist/templates/vite-wagmi-template/src/vite-env.d.ts +1 -0
  88. package/dist/templates/vite-wagmi-template/tsconfig.app.json +25 -0
  89. package/dist/templates/vite-wagmi-template/tsconfig.json +11 -0
  90. package/dist/templates/vite-wagmi-template/tsconfig.node.json +14 -0
  91. package/dist/templates/vite-wagmi-template/vite.config.ts +10 -0
  92. package/dist/templates/vite-wagmi-template/yarn.lock +4603 -0
  93. package/package.json +3 -2
  94. package/src/main.ts +31 -33
  95. package/templates/next-cosmos-template/.eslintrc.json +1 -1
  96. package/templates/next-cosmos-template/next.config.mjs +9 -9
  97. package/templates/next-cosmos-template/package.json +29 -29
  98. package/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +162 -171
  99. package/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +92 -94
  100. package/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +22 -49
  101. package/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
  102. package/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +13 -17
  103. package/templates/next-cosmos-template/src/app/components/index.ts +3 -3
  104. package/templates/next-cosmos-template/src/app/constants/chain.ts +9 -9
  105. package/templates/next-cosmos-template/src/app/constants/index.ts +1 -1
  106. package/templates/next-cosmos-template/src/app/index.css +99 -86
  107. package/templates/next-cosmos-template/src/app/layout.tsx +12 -12
  108. package/templates/next-cosmos-template/src/app/page.tsx +13 -13
  109. package/templates/next-cosmos-template/tsconfig.json +24 -24
  110. package/templates/next-wagmi-template/.eslintrc.json +1 -1
  111. package/templates/next-wagmi-template/package.json +28 -28
  112. package/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +223 -237
  113. package/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +92 -94
  114. package/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +10 -36
  115. package/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +29 -28
  116. package/templates/next-wagmi-template/src/app/components/index.ts +2 -2
  117. package/templates/next-wagmi-template/src/app/constants/chain.ts +2 -2
  118. package/templates/next-wagmi-template/src/app/constants/index.ts +1 -1
  119. package/templates/next-wagmi-template/src/app/index.css +99 -86
  120. package/templates/next-wagmi-template/src/app/layout.tsx +12 -12
  121. package/templates/next-wagmi-template/src/app/page.tsx +17 -17
  122. package/templates/next-wagmi-template/tsconfig.json +24 -24
  123. package/templates/vite-cosmos-template/.eslintrc.cjs +10 -17
  124. package/templates/vite-cosmos-template/package.json +33 -33
  125. package/templates/vite-cosmos-template/src/App.tsx +11 -12
  126. package/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +162 -171
  127. package/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +92 -94
  128. package/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +20 -45
  129. package/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
  130. package/templates/vite-cosmos-template/src/components/Web3Provider.tsx +14 -18
  131. package/templates/vite-cosmos-template/src/components/index.ts +4 -4
  132. package/templates/vite-cosmos-template/src/constants/chain.ts +9 -9
  133. package/templates/vite-cosmos-template/src/constants/index.ts +1 -1
  134. package/templates/vite-cosmos-template/src/index.css +99 -86
  135. package/templates/vite-cosmos-template/src/main.tsx +10 -10
  136. package/templates/vite-cosmos-template/tsconfig.app.json +21 -23
  137. package/templates/vite-cosmos-template/tsconfig.json +9 -9
  138. package/templates/vite-cosmos-template/tsconfig.node.json +11 -11
  139. package/templates/vite-cosmos-template/vite.config.ts +4 -4
  140. package/templates/vite-wagmi-template/.eslintrc.cjs +10 -17
  141. package/templates/vite-wagmi-template/package.json +31 -31
  142. package/templates/vite-wagmi-template/src/App.tsx +12 -13
  143. package/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +225 -239
  144. package/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +92 -94
  145. package/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +28 -53
  146. package/templates/vite-wagmi-template/src/components/Web3Provider.tsx +29 -28
  147. package/templates/vite-wagmi-template/src/constants/chain.ts +1 -1
  148. package/templates/vite-wagmi-template/src/constants/index.ts +1 -1
  149. package/templates/vite-wagmi-template/src/index.css +98 -85
  150. package/templates/vite-wagmi-template/src/main.tsx +10 -10
  151. package/templates/vite-wagmi-template/tsconfig.app.json +21 -23
  152. package/templates/vite-wagmi-template/tsconfig.json +9 -9
  153. package/templates/vite-wagmi-template/tsconfig.node.json +11 -11
  154. package/templates/vite-wagmi-template/vite.config.ts +7 -7
  155. 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 "@sei-js/evm";
4
- import { useState } from "react";
5
- import { ReadContractParameters, formatEther, fromHex, parseEther, toHex } from "viem";
6
- import { useAccount, usePublicClient, useWriteContract } from "wagmi";
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 "./Homepage.css";
8
+ import './Homepage.css';
9
9
 
10
10
  function Examples() {
11
- const [balance, setBalance] = useState('')
12
- const [supply, setSupply] = useState('');
13
- const [count, setCount] = useState(0)
11
+ const [balance, setBalance] = useState('');
12
+ const [supply, setSupply] = useState('');
13
+ const [count, setCount] = useState(0);
14
14
 
15
- const publicClient = usePublicClient();
16
- const { address } = useAccount();
15
+ const publicClient = usePublicClient();
16
+ const { address } = useAccount();
17
17
  const { writeContractAsync } = useWriteContract();
18
18
 
19
- const formatLargeSeiNumber = (num: string, decimals: number): string => {
19
+ const formatLargeSeiNumber = (num: string, decimals: number): string => {
20
20
  if (num.length > 10) {
21
- return (Number(num) / 1000000 / 1000000000).toLocaleString(navigator.language, { minimumFractionDigits: decimals, maximumFractionDigits: decimals}) + ' B';
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
- const copyToClipboard = (text: string) => {
28
- try {
29
- navigator.clipboard.writeText(text);
30
- } catch (err) {
31
- console.error("Failed to copy text: ", err);
32
- } finally {
33
- alert("Copied to clipboard!");
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
- const renderAddressExample = () => {
38
- return (
39
- <div className="card">
40
- <div className="card-header">
41
- <p className="card__title">Wallet address</p>
42
- <small className="card__description">
43
- <a
44
- href="https://viem.sh/docs/clients/public.html"
45
- target="_blank">Viem Public Client</a> query example
46
- </small>
47
- </div>
48
- <div className="card-body">
49
- <div className="content-background space-between">
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
- <button
61
- className="small outline"
62
- onClick={() =>
63
- copyToClipboard(
64
- address as string
65
- )
66
- }
67
- >
68
- Copy
69
- </button>
70
- </div>
71
- </div>
72
- <div className="card-footer">
73
- </div>
74
- </div>
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
- const getBalanceWagmi = async () => {
79
- if (!address || !publicClient) {
80
- return undefined
81
- }
82
- const weiBalance = await publicClient.getBalance({address});
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
- const params: ReadContractParameters = {
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
- // Fetch count of a CosmWasm Contract using WASM Precompile
159
- const fetchCount = async () => {
160
- if (!publicClient) {
161
- return;
162
- }
160
+ const queryMsg = toHex(JSON.stringify({ get_count: {} }));
163
161
 
164
- const COUNTER_CONTRACT_ADDRESS =
165
- "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m";
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
- const queryMsg = toHex(JSON.stringify({ get_count: {} }));
177
+ // Fetch count of a CosmWasm Contract using WASM Precompile
178
+ const incrementCounter = async () => {
179
+ if (!address || !publicClient) {
180
+ return;
181
+ }
168
182
 
169
- const params: ReadContractParameters = {
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
- // Fetch count of a CosmWasm Contract using WASM Precompile
185
- const incrementCounter = async () => {
186
- if (!address || !publicClient) {
187
- return;
188
- }
189
-
190
- const COUNTER_CONTRACT_ADDRESS =
191
- "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m";
192
-
193
- const execMsg = toHex(JSON.stringify({ increment: {} }));
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
- try {
205
- const estimatedGas = await publicClient.estimateContractGas(params);
196
+ try {
197
+ const estimatedGas = await publicClient.estimateContractGas(params);
206
198
 
207
- // Call smart contract execute msg
208
- await writeContractAsync({ ...params, gas: estimatedGas});
199
+ // Call smart contract execute msg
200
+ await writeContractAsync({ ...params, gas: estimatedGas });
209
201
 
210
- // Wait for 1 block to confirm transaction
211
- setTimeout(() => {}, 400);
212
- await fetchCount();
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
- } catch (error) {
215
- console.log(error)
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
- const renderCounterContractExample = () => {
220
- return (
221
- <div className="card">
222
- <div className="card-header">
223
- <p className="card__title">Smart contract interaction</p>
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
- {/* Second card */}
259
- {renderBalanceExample()}
244
+ {/* Second card */}
245
+ {renderBalanceExample()}
260
246
 
261
- {/* Third card */}
262
- {renderBankSupplyExample()}
247
+ {/* Third card */}
248
+ {renderBankSupplyExample()}
263
249
 
264
- {/* Fourth card */}
265
- {renderCounterContractExample()}
266
- </div>
267
- </div>
268
- )
250
+ {/* Fourth card */}
251
+ {renderCounterContractExample()}
252
+ </div>
253
+ </div>
254
+ );
269
255
  }
270
256
 
271
257
  export default Examples;