@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,18 +1,11 @@
1
1
  module.exports = {
2
- root: true,
3
- env: { browser: true, es2020: true },
4
- extends: [
5
- 'eslint:recommended',
6
- 'plugin:@typescript-eslint/recommended',
7
- 'plugin:react-hooks/recommended',
8
- ],
9
- ignorePatterns: ['dist', '.eslintrc.cjs'],
10
- parser: '@typescript-eslint/parser',
11
- plugins: ['react-refresh'],
12
- rules: {
13
- 'react-refresh/only-export-components': [
14
- 'warn',
15
- { allowConstantExport: true },
16
- ],
17
- },
18
- }
2
+ root: true,
3
+ env: { browser: true, es2020: true },
4
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended'],
5
+ ignorePatterns: ['dist', '.eslintrc.cjs'],
6
+ parser: '@typescript-eslint/parser',
7
+ plugins: ['react-refresh'],
8
+ rules: {
9
+ 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }]
10
+ }
11
+ };
@@ -1,33 +1,33 @@
1
1
  {
2
- "name": "template-vite-wagmi-sei-app",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "tsc -b && vite build",
9
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10
- "preview": "vite preview"
11
- },
12
- "dependencies": {
13
- "@rainbow-me/rainbowkit": "^2.1.2",
14
- "@sei-js/evm": "^1.2.0",
15
- "@tanstack/react-query": "^5.45.1",
16
- "react": "^18.3.1",
17
- "react-dom": "^18.3.1",
18
- "viem": "^2.15.1",
19
- "wagmi": "^2.10.2"
20
- },
21
- "devDependencies": {
22
- "@types/react": "^18.3.3",
23
- "@types/react-dom": "^18.3.0",
24
- "@typescript-eslint/eslint-plugin": "^7.13.1",
25
- "@typescript-eslint/parser": "^7.13.1",
26
- "@vitejs/plugin-react": "^4.3.1",
27
- "eslint": "^8.57.0",
28
- "eslint-plugin-react-hooks": "^4.6.2",
29
- "eslint-plugin-react-refresh": "^0.4.7",
30
- "typescript": "^5.2.2",
31
- "vite": "^5.3.1"
32
- }
2
+ "name": "template-vite-wagmi-sei-app",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc -b && vite build",
9
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10
+ "preview": "vite preview"
11
+ },
12
+ "dependencies": {
13
+ "@rainbow-me/rainbowkit": "^2.1.2",
14
+ "@sei-js/evm": "^1.2.0",
15
+ "@tanstack/react-query": "^5.45.1",
16
+ "react": "^18.3.1",
17
+ "react-dom": "^18.3.1",
18
+ "viem": "^2.15.1",
19
+ "wagmi": "^2.10.2"
20
+ },
21
+ "devDependencies": {
22
+ "@types/react": "^18.3.3",
23
+ "@types/react-dom": "^18.3.0",
24
+ "@typescript-eslint/eslint-plugin": "^7.13.1",
25
+ "@typescript-eslint/parser": "^7.13.1",
26
+ "@vitejs/plugin-react": "^4.3.1",
27
+ "eslint": "^8.57.0",
28
+ "eslint-plugin-react-hooks": "^4.6.2",
29
+ "eslint-plugin-react-refresh": "^0.4.7",
30
+ "typescript": "^5.2.2",
31
+ "vite": "^5.3.1"
32
+ }
33
33
  }
@@ -1,21 +1,20 @@
1
- import './index.css'
1
+ import './index.css';
2
2
  import { ConnectButton } from '@rainbow-me/rainbowkit';
3
3
  import Homepage from './components/Homepage/Homepage';
4
4
 
5
5
  function App() {
6
-
7
6
  return (
8
- <>
9
- <div className="header">
10
- <ConnectButton
11
- showBalance={{
12
- smallScreen: false,
13
- largeScreen: true,
14
- }}
15
- />
16
- </div>
17
- <Homepage/>
18
- </>
7
+ <>
8
+ <div className="header">
9
+ <ConnectButton
10
+ showBalance={{
11
+ smallScreen: false,
12
+ largeScreen: true
13
+ }}
14
+ />
15
+ </div>
16
+ <Homepage />
17
+ </>
19
18
  );
20
19
  }
21
20
 
@@ -1,269 +1,255 @@
1
- import { BANK_PRECOMPILE_ABI, BANK_PRECOMPILE_ADDRESS, WASM_PRECOMPILE_ABI, WASM_PRECOMPILE_ADDRESS } from "@sei-js/evm";
2
- import { useState } from "react";
3
- import { ReadContractParameters, formatEther, fromHex, parseEther, toHex } from "viem";
4
- import { useAccount, usePublicClient, useWriteContract } from "wagmi";
1
+ import { BANK_PRECOMPILE_ABI, BANK_PRECOMPILE_ADDRESS, WASM_PRECOMPILE_ABI, WASM_PRECOMPILE_ADDRESS } from '@sei-js/evm';
2
+ import { useState } from 'react';
3
+ import { ReadContractParameters, formatEther, fromHex, parseEther, toHex } from 'viem';
4
+ import { useAccount, usePublicClient, useWriteContract } from 'wagmi';
5
5
 
6
- import "./Homepage.css";
6
+ import './Homepage.css';
7
7
 
8
8
  function Examples() {
9
- const [balance, setBalance] = useState('')
10
- const [supply, setSupply] = useState('');
11
- const [count, setCount] = useState(0)
9
+ const [balance, setBalance] = useState('');
10
+ const [supply, setSupply] = useState('');
11
+ const [count, setCount] = useState(0);
12
12
 
13
- const publicClient = usePublicClient();
14
- const { address } = useAccount();
13
+ const publicClient = usePublicClient();
14
+ const { address } = useAccount();
15
15
  const { writeContractAsync } = useWriteContract();
16
16
 
17
- const formatLargeSeiNumber = (num: string, decimals: number): string => {
17
+ const formatLargeSeiNumber = (num: string, decimals: number): string => {
18
18
  if (num.length > 10) {
19
- return (Number(num) / 1000000 / 1000000000).toLocaleString(navigator.language, { minimumFractionDigits: decimals, maximumFractionDigits: decimals}) + ' B';
19
+ return (
20
+ (Number(num) / 1000000 / 1000000000).toLocaleString(navigator.language, { minimumFractionDigits: decimals, maximumFractionDigits: decimals }) + ' B'
21
+ );
20
22
  } else {
21
23
  return (Number(num) / 1000000).toLocaleString(navigator.language);
22
24
  }
23
25
  };
24
26
 
25
- const copyToClipboard = (text: string) => {
26
- try {
27
- navigator.clipboard.writeText(text);
28
- } catch (err) {
29
- console.error("Failed to copy text: ", err);
30
- } finally {
31
- alert("Copied to clipboard!");
32
- }
33
- }
34
-
35
- const renderAddressExample = () => {
36
- return (
37
- <div className="card">
38
- <div className="card-header">
39
- <p className="card__title">Wallet address</p>
40
- <small className="card__description">
41
- <a
42
- href="https://viem.sh/docs/clients/public.html"
43
- target="_blank">Viem Public Client</a> query example
44
- </small>
45
- </div>
46
- <div className="card-body">
47
- <div className="content-background space-between">
48
- {
49
- address ?
50
- <div>
51
- <p className="card-footer">
52
- {address}
53
- </p>
54
- </div> :
55
- <a> --- </a>
56
- }
57
-
58
- <button
59
- className="small outline"
60
- onClick={() =>
61
- copyToClipboard(
62
- address as string
63
- )
64
- }
65
- >
66
- Copy
67
- </button>
68
- </div>
69
- </div>
70
- <div className="card-footer">
71
- </div>
72
- </div>
73
- )
74
- }
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
+ };
75
36
 
76
- const getBalanceWagmi = async () => {
77
- if (!address || !publicClient) {
78
- return undefined
79
- }
80
- const weiBalance = await publicClient.getBalance({address});
81
- const seiBalance = formatEther(weiBalance)
82
- setBalance(seiBalance);
83
- }
84
-
85
- const renderBalanceExample = () => {
86
- return (
87
- <div className="card">
88
- <div className="card-header">
89
- <p className="card__title">Wallet balance</p>
90
- <small className="card__description">
91
- <a
92
- href="https://viem.sh/docs/clients/public.html"
93
- target="_blank">Viem Public Client</a> query example
94
- </small>
95
- </div>
96
- <div className="card-body">
97
- <div className="content-background space-between">
98
- <small>SEI</small>
99
- <p>{balance ? balance : '---' } SEI</p>
100
- </div>
101
- </div>
102
- <div className="card-footer">
103
- <button onClick={getBalanceWagmi}>Fetch balance</button>
104
- </div>
105
- </div>
106
- )
107
- }
108
-
109
- // Example of using precompiles to query native Sei modules.
110
- const getBankSupply = async () => {
111
- if (!publicClient) {
112
- return;
113
- }
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 href="https://viem.sh/docs/clients/public.html" target="_blank">
44
+ Viem Public Client
45
+ </a>{' '}
46
+ query example
47
+ </small>
48
+ </div>
49
+ <div className="card-body">
50
+ <div className="content-background space-between">
51
+ {address ? (
52
+ <div>
53
+ <p className="card-footer">{address}</p>
54
+ </div>
55
+ ) : (
56
+ <a> --- </a>
57
+ )}
58
+
59
+ <button className="small outline" onClick={() => copyToClipboard(address as string)}>
60
+ Copy
61
+ </button>
62
+ </div>
63
+ </div>
64
+ <div className="card-footer"></div>
65
+ </div>
66
+ );
67
+ };
114
68
 
115
- const params: ReadContractParameters = {
116
- address: BANK_PRECOMPILE_ADDRESS,
117
- abi: BANK_PRECOMPILE_ABI,
118
- functionName: 'supply',
119
- args: ['usei']
120
- }
121
- try {
122
- const response = await publicClient.readContract(params) as BigInt;
123
- const supply = formatLargeSeiNumber(response.toString(), 1)
124
- setSupply(supply);
125
- } catch (e) {
126
- console.log(e);
127
- }
128
- }
129
-
130
- const renderBankSupplyExample = () => {
131
- return (
132
- <div className="card">
133
- <div className="card-header">
134
- <p className="card__title">Total Sei supply</p>
135
- <small className="card__description">
136
- <a
137
- href="https://www.docs.sei.io/dev-interoperability/precompiles/bank"
138
- target="_blank"> Bank precompile
139
- </a> example for querying native Sei
140
- modules
141
- </small>
142
- </div>
143
- <div className="card-body">
144
- <div className="content-background space-between">
145
- <small>SEI</small>
146
- <p>{supply}</p>
147
- </div>
148
- </div>
149
- <div className="card-footer">
150
- <button onClick={getBankSupply}>Fetch supply</button>
151
- </div>
152
- </div>
153
- )
154
- }
69
+ const getBalanceWagmi = async () => {
70
+ if (!address || !publicClient) {
71
+ return undefined;
72
+ }
73
+ const weiBalance = await publicClient.getBalance({ address });
74
+ const seiBalance = formatEther(weiBalance);
75
+ setBalance(seiBalance);
76
+ };
155
77
 
156
- // Fetch count of a CosmWasm Contract using WASM Precompile
157
- const fetchCount = async () => {
158
- if (!publicClient) {
159
- return;
160
- }
78
+ const renderBalanceExample = () => {
79
+ return (
80
+ <div className="card">
81
+ <div className="card-header">
82
+ <p className="card__title">Wallet balance</p>
83
+ <small className="card__description">
84
+ <a href="https://viem.sh/docs/clients/public.html" target="_blank">
85
+ Viem Public Client
86
+ </a>{' '}
87
+ query example
88
+ </small>
89
+ </div>
90
+ <div className="card-body">
91
+ <div className="content-background space-between">
92
+ <small>SEI</small>
93
+ <p>{balance ? balance : '---'} SEI</p>
94
+ </div>
95
+ </div>
96
+ <div className="card-footer">
97
+ <button onClick={getBalanceWagmi}>Fetch balance</button>
98
+ </div>
99
+ </div>
100
+ );
101
+ };
161
102
 
162
- const COUNTER_CONTRACT_ADDRESS =
163
- "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m";
103
+ // Example of using precompiles to query native Sei modules.
104
+ const getBankSupply = async () => {
105
+ if (!publicClient) {
106
+ return;
107
+ }
164
108
 
165
- const queryMsg = toHex(JSON.stringify({ get_count: {} }));
109
+ const params: ReadContractParameters = {
110
+ address: BANK_PRECOMPILE_ADDRESS,
111
+ abi: BANK_PRECOMPILE_ABI,
112
+ functionName: 'supply',
113
+ args: ['usei']
114
+ };
115
+ try {
116
+ const response = (await publicClient.readContract(params)) as BigInt;
117
+ const supply = formatLargeSeiNumber(response.toString(), 1);
118
+ setSupply(supply);
119
+ } catch (e) {
120
+ console.log(e);
121
+ }
122
+ };
166
123
 
167
- const params: ReadContractParameters = {
168
- address: WASM_PRECOMPILE_ADDRESS,
169
- abi: WASM_PRECOMPILE_ABI,
170
- functionName: 'query',
171
- args: [COUNTER_CONTRACT_ADDRESS, queryMsg]
172
- }
173
- try {
174
- const response = await publicClient?.readContract(params) as `0x${string}`;
175
- const { count } = JSON.parse(fromHex(response, 'string'));
176
- setCount(count);
177
- } catch (e) {
178
- console.log(e);
179
- }
180
- }
124
+ const renderBankSupplyExample = () => {
125
+ return (
126
+ <div className="card">
127
+ <div className="card-header">
128
+ <p className="card__title">Total Sei supply</p>
129
+ <small className="card__description">
130
+ <a href="https://www.docs.sei.io/dev-interoperability/precompiles/bank" target="_blank">
131
+ {' '}
132
+ Bank precompile
133
+ </a>{' '}
134
+ example for querying native Sei modules
135
+ </small>
136
+ </div>
137
+ <div className="card-body">
138
+ <div className="content-background space-between">
139
+ <small>SEI</small>
140
+ <p>{supply}</p>
141
+ </div>
142
+ </div>
143
+ <div className="card-footer">
144
+ <button onClick={getBankSupply}>Fetch supply</button>
145
+ </div>
146
+ </div>
147
+ );
148
+ };
181
149
 
182
- // Fetch count of a CosmWasm Contract using WASM Precompile
183
- const incrementCounter = async () => {
184
- if (!address || !publicClient) {
185
- return;
186
- }
187
-
188
- const COUNTER_CONTRACT_ADDRESS =
189
- "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m";
190
-
191
- const execMsg = toHex(JSON.stringify({ increment: {} }));
192
- const coins = toHex('[]')
193
- const params = {
194
- account: address,
195
- address: WASM_PRECOMPILE_ADDRESS,
196
- abi: WASM_PRECOMPILE_ABI,
197
- functionName: 'execute',
198
- args: [COUNTER_CONTRACT_ADDRESS, execMsg, coins],
199
- value: parseEther('0')
200
- }
150
+ // Fetch count of a CosmWasm Contract using WASM Precompile
151
+ const fetchCount = async () => {
152
+ if (!publicClient) {
153
+ return;
154
+ }
201
155
 
202
- try {
203
- const estimatedGas = await publicClient.estimateContractGas(params);
156
+ const COUNTER_CONTRACT_ADDRESS = 'sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m';
157
+
158
+ const queryMsg = toHex(JSON.stringify({ get_count: {} }));
159
+
160
+ const params: ReadContractParameters = {
161
+ address: WASM_PRECOMPILE_ADDRESS,
162
+ abi: WASM_PRECOMPILE_ABI,
163
+ functionName: 'query',
164
+ args: [COUNTER_CONTRACT_ADDRESS, queryMsg]
165
+ };
166
+ try {
167
+ const response = (await publicClient?.readContract(params)) as `0x${string}`;
168
+ const { count } = JSON.parse(fromHex(response, 'string'));
169
+ setCount(count);
170
+ } catch (e) {
171
+ console.log(e);
172
+ }
173
+ };
204
174
 
205
- // Call smart contract execute msg
206
- await writeContractAsync({ ...params, gas: estimatedGas});
175
+ // Fetch count of a CosmWasm Contract using WASM Precompile
176
+ const incrementCounter = async () => {
177
+ if (!address || !publicClient) {
178
+ return;
179
+ }
207
180
 
208
- // Wait for 1 block to confirm transaction
209
- setTimeout(() => {}, 400);
210
- await fetchCount();
181
+ const COUNTER_CONTRACT_ADDRESS = 'sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m';
182
+
183
+ const execMsg = toHex(JSON.stringify({ increment: {} }));
184
+ const coins = toHex('[]');
185
+ const params = {
186
+ account: address,
187
+ address: WASM_PRECOMPILE_ADDRESS,
188
+ abi: WASM_PRECOMPILE_ABI,
189
+ functionName: 'execute',
190
+ args: [COUNTER_CONTRACT_ADDRESS, execMsg, coins],
191
+ value: parseEther('0')
192
+ };
193
+
194
+ try {
195
+ const estimatedGas = await publicClient.estimateContractGas(params);
196
+
197
+ // Call smart contract execute msg
198
+ await writeContractAsync({ ...params, gas: estimatedGas });
199
+
200
+ // Wait for 1 block to confirm transaction
201
+ setTimeout(() => {}, 400);
202
+ await fetchCount();
203
+ } catch (error) {
204
+ console.log(error);
205
+ }
206
+ };
211
207
 
212
- } catch (error) {
213
- console.log(error)
214
- }
215
- };
208
+ const renderCounterContractExample = () => {
209
+ return (
210
+ <div className="card">
211
+ <div className="card-header">
212
+ <p className="card__title">Smart contract interaction</p>
213
+ <small>
214
+ <a href="https://www.docs.sei.io/dev-interoperability/precompiles/cosmwasm" target="_blank">
215
+ WASM Precompile
216
+ </a>{' '}
217
+ example of CosmWasm smart contract interaction
218
+ </small>
219
+ </div>
220
+ <div className="card-body">
221
+ <div className="content-background space-between">
222
+ <small>Count</small>
223
+ <p>{count}</p>
224
+ <button className="small outline" onClick={incrementCounter}>
225
+ Increase
226
+ </button>
227
+ </div>
228
+ </div>
229
+ <div className="card-footer">
230
+ <button onClick={fetchCount}>Fetch count</button>
231
+ </div>
232
+ </div>
233
+ );
234
+ };
216
235
 
217
- const renderCounterContractExample = () => {
218
- return (
219
- <div className="card">
220
- <div className="card-header">
221
- <p className="card__title">Smart contract interaction</p>
222
- <small>
223
- <a
224
- href="https://www.docs.sei.io/dev-interoperability/precompiles/cosmwasm"
225
- target="_blank">
226
- WASM Precompile
227
- </a> example of CosmWasm smart
228
- contract interaction
229
- </small>
230
- </div>
231
- <div className="card-body">
232
- <div className="content-background space-between">
233
- <small>Count</small>
234
- <p>{count}</p>
235
- <button
236
- className="small outline"
237
- onClick={incrementCounter}
238
- >
239
- Increase
240
- </button>
241
- </div>
242
- </div>
243
- <div className="card-footer">
244
- <button onClick={fetchCount}>Fetch count</button>
245
- </div>
246
- </div>
247
- )
248
- }
249
-
250
- return (
251
- <div className="container">
252
- <div className="grid">
253
- {/* First card */}
254
- {renderAddressExample()}
236
+ return (
237
+ <div className="container">
238
+ <div className="grid">
239
+ {/* First card */}
240
+ {renderAddressExample()}
255
241
 
256
- {/* Second card */}
257
- {renderBalanceExample()}
242
+ {/* Second card */}
243
+ {renderBalanceExample()}
258
244
 
259
- {/* Third card */}
260
- {renderBankSupplyExample()}
245
+ {/* Third card */}
246
+ {renderBankSupplyExample()}
261
247
 
262
- {/* Fourth card */}
263
- {renderCounterContractExample()}
264
- </div>
265
- </div>
266
- )
248
+ {/* Fourth card */}
249
+ {renderCounterContractExample()}
250
+ </div>
251
+ </div>
252
+ );
267
253
  }
268
254
 
269
255
  export default Examples;