@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.
- package/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +12 -0
- package/README.md +16 -25
- package/biome.json +8 -0
- package/dist/main.js +162 -0
- package/dist/templates/next-cosmos-template/.eslintrc.json +3 -0
- package/dist/templates/next-cosmos-template/README.md +60 -0
- package/dist/templates/next-cosmos-template/next-env.d.ts +5 -0
- package/dist/templates/next-cosmos-template/next.config.mjs +14 -0
- package/dist/templates/next-cosmos-template/package.json +31 -0
- package/dist/templates/next-cosmos-template/public/next.svg +1 -0
- package/dist/templates/next-cosmos-template/public/sei-logotype.svg +15 -0
- package/dist/templates/next-cosmos-template/public/vercel.svg +1 -0
- package/dist/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +168 -0
- package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +154 -0
- package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +83 -0
- package/dist/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +18 -0
- package/dist/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +35 -0
- package/dist/templates/next-cosmos-template/src/app/components/index.ts +3 -0
- package/dist/templates/next-cosmos-template/src/app/constants/chain.ts +16 -0
- package/dist/templates/next-cosmos-template/src/app/constants/index.ts +1 -0
- package/dist/templates/next-cosmos-template/src/app/favicon.ico +0 -0
- package/dist/templates/next-cosmos-template/src/app/index.css +184 -0
- package/dist/templates/next-cosmos-template/src/app/layout.tsx +21 -0
- package/dist/templates/next-cosmos-template/src/app/page.tsx +17 -0
- package/dist/templates/next-cosmos-template/tsconfig.json +26 -0
- package/dist/templates/next-cosmos-template/yarn.lock +9814 -0
- package/dist/templates/next-wagmi-template/.eslintrc.json +3 -0
- package/dist/templates/next-wagmi-template/README.md +58 -0
- package/dist/templates/next-wagmi-template/next-env.d.ts +5 -0
- package/dist/templates/next-wagmi-template/next.config.mjs +4 -0
- package/dist/templates/next-wagmi-template/package.json +30 -0
- package/dist/templates/next-wagmi-template/public/sei-logotype.svg +15 -0
- package/dist/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +257 -0
- package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +154 -0
- package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +87 -0
- package/dist/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +74 -0
- package/dist/templates/next-wagmi-template/src/app/components/index.ts +2 -0
- package/dist/templates/next-wagmi-template/src/app/constants/chain.ts +7 -0
- package/dist/templates/next-wagmi-template/src/app/constants/index.ts +1 -0
- package/dist/templates/next-wagmi-template/src/app/favicon.ico +0 -0
- package/dist/templates/next-wagmi-template/src/app/index.css +184 -0
- package/dist/templates/next-wagmi-template/src/app/layout.tsx +21 -0
- package/dist/templates/next-wagmi-template/src/app/page.tsx +21 -0
- package/dist/templates/next-wagmi-template/tsconfig.json +26 -0
- package/dist/templates/next-wagmi-template/yarn.lock +4809 -0
- package/dist/templates/vite-cosmos-template/.eslintrc.cjs +11 -0
- package/dist/templates/vite-cosmos-template/README.md +72 -0
- package/dist/templates/vite-cosmos-template/favicon.ico +0 -0
- package/dist/templates/vite-cosmos-template/index.html +16 -0
- package/dist/templates/vite-cosmos-template/package.json +35 -0
- package/dist/templates/vite-cosmos-template/public/sei-logotype.svg +15 -0
- package/dist/templates/vite-cosmos-template/src/App.tsx +15 -0
- package/dist/templates/vite-cosmos-template/src/assets/react.svg +1 -0
- package/dist/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +168 -0
- package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +154 -0
- package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +77 -0
- package/dist/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +18 -0
- package/dist/templates/vite-cosmos-template/src/components/Web3Provider.tsx +41 -0
- package/dist/templates/vite-cosmos-template/src/components/index.ts +4 -0
- package/dist/templates/vite-cosmos-template/src/constants/chain.ts +16 -0
- package/dist/templates/vite-cosmos-template/src/constants/index.ts +1 -0
- package/dist/templates/vite-cosmos-template/src/index.css +184 -0
- package/dist/templates/vite-cosmos-template/src/main.tsx +12 -0
- package/dist/templates/vite-cosmos-template/src/vite-env.d.ts +1 -0
- package/dist/templates/vite-cosmos-template/tsconfig.app.json +25 -0
- package/dist/templates/vite-cosmos-template/tsconfig.json +11 -0
- package/dist/templates/vite-cosmos-template/tsconfig.node.json +14 -0
- package/dist/templates/vite-cosmos-template/vite.config.ts +7 -0
- package/dist/templates/vite-cosmos-template/yarn.lock +9323 -0
- package/dist/templates/vite-wagmi-template/.eslintrc.cjs +11 -0
- package/dist/templates/vite-wagmi-template/README.md +72 -0
- package/dist/templates/vite-wagmi-template/favicon.ico +0 -0
- package/dist/templates/vite-wagmi-template/index.html +12 -0
- package/dist/templates/vite-wagmi-template/package.json +33 -0
- package/dist/templates/vite-wagmi-template/public/sei-logotype.svg +15 -0
- package/dist/templates/vite-wagmi-template/src/App.tsx +21 -0
- package/dist/templates/vite-wagmi-template/src/assets/react.svg +1 -0
- package/dist/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +255 -0
- package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +154 -0
- package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +81 -0
- package/dist/templates/vite-wagmi-template/src/components/Web3Provider.tsx +72 -0
- package/dist/templates/vite-wagmi-template/src/constants/chain.ts +6 -0
- package/dist/templates/vite-wagmi-template/src/constants/index.ts +1 -0
- package/dist/templates/vite-wagmi-template/src/index.css +183 -0
- package/dist/templates/vite-wagmi-template/src/main.tsx +12 -0
- package/dist/templates/vite-wagmi-template/src/vite-env.d.ts +1 -0
- package/dist/templates/vite-wagmi-template/tsconfig.app.json +25 -0
- package/dist/templates/vite-wagmi-template/tsconfig.json +11 -0
- package/dist/templates/vite-wagmi-template/tsconfig.node.json +14 -0
- package/dist/templates/vite-wagmi-template/vite.config.ts +10 -0
- package/dist/templates/vite-wagmi-template/yarn.lock +4603 -0
- 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
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sei-js/create-sei",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"module": "dist/main.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/main.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc && cp -r ./templates ./dist/templates",
|
|
9
|
-
"dev": "node --loader ts-node/esm src/main.ts"
|
|
9
|
+
"dev": "node --loader ts-node/esm src/main.ts",
|
|
10
|
+
"docs": "typedoc --out docs"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
13
|
"boxen": "^7.1.1",
|
package/src/main.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
2
|
import boxen from 'boxen';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { dirname } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { Command } from 'commander';
|
|
10
10
|
|
|
11
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -23,8 +23,7 @@ const printWelcomeMessage = () => {
|
|
|
23
23
|
borderColor: '#932C23'
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
};
|
|
28
27
|
|
|
29
28
|
enum FrontendScaffolding {
|
|
30
29
|
Vite = 'vite',
|
|
@@ -48,7 +47,7 @@ interface WizardOptions {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
const promptFramework = async () => {
|
|
51
|
-
const {appFramework} = await inquirer.prompt([
|
|
50
|
+
const { appFramework } = await inquirer.prompt([
|
|
52
51
|
{
|
|
53
52
|
type: 'list',
|
|
54
53
|
name: 'appFramework',
|
|
@@ -58,10 +57,10 @@ const promptFramework = async () => {
|
|
|
58
57
|
]);
|
|
59
58
|
|
|
60
59
|
return appFramework;
|
|
61
|
-
}
|
|
60
|
+
};
|
|
62
61
|
|
|
63
62
|
const promptRpcIntegrations = async () => {
|
|
64
|
-
const {rpcIntegrationType} = await inquirer.prompt([
|
|
63
|
+
const { rpcIntegrationType } = await inquirer.prompt([
|
|
65
64
|
{
|
|
66
65
|
type: 'list',
|
|
67
66
|
name: 'rpcIntegrationType',
|
|
@@ -74,7 +73,7 @@ const promptRpcIntegrations = async () => {
|
|
|
74
73
|
};
|
|
75
74
|
|
|
76
75
|
const promptEVMLibrary = async () => {
|
|
77
|
-
const {evmLibrary} = await inquirer.prompt([
|
|
76
|
+
const { evmLibrary } = await inquirer.prompt([
|
|
78
77
|
{
|
|
79
78
|
type: 'list',
|
|
80
79
|
name: 'evmLibrary',
|
|
@@ -87,19 +86,20 @@ const promptEVMLibrary = async () => {
|
|
|
87
86
|
};
|
|
88
87
|
|
|
89
88
|
function isValidDirectoryName(dirName) {
|
|
90
|
-
const illegalRe = /[<>:"
|
|
89
|
+
const illegalRe = /[<>:"/\\|?*]/g;
|
|
91
90
|
const windowsReservedRe = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
|
|
92
91
|
const trailingRe = /[. ]+$/;
|
|
93
92
|
const validNpmPackageRe = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
94
|
-
|
|
93
|
+
|
|
95
94
|
if (typeof dirName !== 'string' || dirName.length === 0) {
|
|
96
|
-
|
|
95
|
+
return false;
|
|
97
96
|
}
|
|
98
|
-
|
|
97
|
+
|
|
98
|
+
// Check for illegal characters, Windows reserved names, trailing spaces/dots
|
|
99
99
|
if (illegalRe.test(dirName) || windowsReservedRe.test(dirName) || trailingRe.test(dirName) || !validNpmPackageRe.test(dirName)) {
|
|
100
|
-
|
|
100
|
+
return false;
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
return true;
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -138,20 +138,19 @@ const validateOptions = (options: WizardOptions): boolean => {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
return valid;
|
|
141
|
-
}
|
|
141
|
+
};
|
|
142
142
|
|
|
143
143
|
async function runWizard(options: WizardOptions): Promise<void> {
|
|
144
144
|
if (!validateOptions(options)) {
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
printWelcomeMessage();
|
|
149
149
|
|
|
150
150
|
let dAppName = '';
|
|
151
151
|
if (options.name) {
|
|
152
|
-
dAppName = options.name
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
152
|
+
dAppName = options.name;
|
|
153
|
+
} else {
|
|
155
154
|
const promptResult = await inquirer.prompt([
|
|
156
155
|
{
|
|
157
156
|
type: 'input',
|
|
@@ -163,19 +162,19 @@ async function runWizard(options: WizardOptions): Promise<void> {
|
|
|
163
162
|
}
|
|
164
163
|
]);
|
|
165
164
|
|
|
166
|
-
dAppName = promptResult.dAppName
|
|
167
|
-
}
|
|
165
|
+
dAppName = promptResult.dAppName;
|
|
166
|
+
}
|
|
168
167
|
|
|
169
|
-
const appFramework = options.framework || await promptFramework();
|
|
170
|
-
let appConnectionType = options.ecosystem || await promptRpcIntegrations();
|
|
171
|
-
if (appConnectionType
|
|
172
|
-
appConnectionType = options.library || await promptEVMLibrary();
|
|
168
|
+
const appFramework = options.framework || (await promptFramework());
|
|
169
|
+
let appConnectionType = options.ecosystem || (await promptRpcIntegrations());
|
|
170
|
+
if (appConnectionType === RPCIntegrationType.EVM) {
|
|
171
|
+
appConnectionType = options.library || (await promptEVMLibrary());
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
const templateName = `${appFramework}-${appConnectionType}-template`;
|
|
176
|
-
const templatePath = path.join(__dirname, 'templates', templateName)
|
|
177
|
-
const dst = path.join(process.cwd(), dAppName)
|
|
178
|
-
await fs.promises.cp(templatePath,
|
|
175
|
+
const templatePath = path.join(__dirname, 'templates', templateName);
|
|
176
|
+
const dst = path.join(process.cwd(), dAppName);
|
|
177
|
+
await fs.promises.cp(templatePath, dst, { recursive: true });
|
|
179
178
|
|
|
180
179
|
console.log(`Project setup complete! Using template ${templateName}\n`);
|
|
181
180
|
console.log(`To start your app, run: \n > cd ${dAppName} \n > yarn \n > yarn dev\n`);
|
|
@@ -184,7 +183,7 @@ async function runWizard(options: WizardOptions): Promise<void> {
|
|
|
184
183
|
program
|
|
185
184
|
.command('app')
|
|
186
185
|
.description('Create a new SEI dApp')
|
|
187
|
-
.option('-n, --name <name>',
|
|
186
|
+
.option('-n, --name <name>', 'Specify the name of your dApp. Name must be a valid package name.')
|
|
188
187
|
.option('-f, --framework <framework>', `Specify the app framework to use: [${Object.values(FrontendScaffolding).join(', ')}]`)
|
|
189
188
|
.option('-e, --ecosystem <ecosystem>', `Specify the ecosystem to use: [${Object.values(RPCIntegrationType).join(', ')}]`)
|
|
190
189
|
.option('-l, --library <library>', `Specify the EVM library to use: [${Object.values(EVMLibrary).join(', ')}]. Only used if ecosystem chosen is 'EVM'`)
|
|
@@ -197,4 +196,3 @@ program
|
|
|
197
196
|
});
|
|
198
197
|
|
|
199
198
|
program.parse(process.argv);
|
|
200
|
-
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/** @type {import('next').NextConfig} */
|
|
2
2
|
const nextConfig = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
images: {
|
|
4
|
+
remotePatterns: [
|
|
5
|
+
{
|
|
6
|
+
protocol: 'https',
|
|
7
|
+
hostname: 'cdn.sei.io',
|
|
8
|
+
port: ''
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export default nextConfig;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
"name": "template-next-cosmos-sei-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start",
|
|
9
|
+
"lint": "next lint"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@cosmos-kit/react": "^2.17.0",
|
|
13
|
+
"@interchain-ui/react": "1.23.21",
|
|
14
|
+
"@interchain-ui/react-no-ssr": "^0.1.4",
|
|
15
|
+
"@sei-js/cosmjs": "^1.0.7",
|
|
16
|
+
"@tanstack/react-query": "^5.45.1",
|
|
17
|
+
"chain-registry": "^1.63.5",
|
|
18
|
+
"cosmos-kit": "^2.18.0",
|
|
19
|
+
"next": "14.2.4",
|
|
20
|
+
"pino-pretty": "^11.2.1",
|
|
21
|
+
"react": "^18",
|
|
22
|
+
"react-dom": "^18"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^20",
|
|
26
|
+
"@types/react": "^18",
|
|
27
|
+
"@types/react-dom": "^18",
|
|
28
|
+
"eslint-config-next": "14.2.4",
|
|
29
|
+
"typescript": "^5"
|
|
30
|
+
}
|
|
31
31
|
}
|
|
@@ -1,177 +1,168 @@
|
|
|
1
|
-
import { getCosmWasmClient, getQueryClient, getSigningCosmWasmClient, getStargateClient } from
|
|
2
|
-
import { useState } from
|
|
3
|
-
import { defaultUrls, selectedChain } from
|
|
4
|
-
import { useChain } from
|
|
1
|
+
import { getCosmWasmClient, getQueryClient, getSigningCosmWasmClient, getStargateClient } from '@sei-js/cosmjs';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { defaultUrls, selectedChain } from '../../constants';
|
|
4
|
+
import { useChain } from '@cosmos-kit/react';
|
|
5
5
|
|
|
6
|
-
import './Homepage.css'
|
|
6
|
+
import './Homepage.css';
|
|
7
7
|
type ExampleProps = {
|
|
8
|
-
|
|
9
|
-
}
|
|
8
|
+
chainId: string;
|
|
9
|
+
};
|
|
10
10
|
|
|
11
11
|
function Examples({ chainId }: ExampleProps) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return (
|
|
169
|
-
<div className="grid">
|
|
170
|
-
{renderBalanceExample()}
|
|
171
|
-
{renderStakingPoolExample()}
|
|
172
|
-
{renderCounterContractExample()}
|
|
173
|
-
</div>
|
|
174
|
-
)
|
|
12
|
+
const [balance, setBalance] = useState(0);
|
|
13
|
+
const [pool, setPool] = useState({ bonded_tokens: 0, not_bonded_tokens: 0 });
|
|
14
|
+
const [count, setCount] = useState(0);
|
|
15
|
+
|
|
16
|
+
const { address, getOfflineSignerAmino } = useChain(selectedChain.chain_name);
|
|
17
|
+
|
|
18
|
+
// Example of using the query client to query Sei modules
|
|
19
|
+
const getStakingPool = async () => {
|
|
20
|
+
const queryClient = await getQueryClient(defaultUrls[chainId].rest);
|
|
21
|
+
const result = await queryClient.cosmos.staking.v1beta1.pool({});
|
|
22
|
+
setPool(result.pool);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const renderStakingPoolExample = () => {
|
|
26
|
+
return (
|
|
27
|
+
<div className="card">
|
|
28
|
+
<div className="card-header">
|
|
29
|
+
<p className="card__title">Staking Pool</p>
|
|
30
|
+
<small className="card__description">
|
|
31
|
+
<a href="https://sei-protocol.github.io/sei-js/functions/cosmjs.getQueryClient.html" target="_blank">
|
|
32
|
+
Sei QueryClient
|
|
33
|
+
</a>{' '}
|
|
34
|
+
query example
|
|
35
|
+
</small>
|
|
36
|
+
</div>
|
|
37
|
+
<div className="card-body">
|
|
38
|
+
<div className="content-background space-between">
|
|
39
|
+
<small>Bonded Tokens</small>
|
|
40
|
+
<p>{pool ? pool.bonded_tokens : '---'} SEI</p>
|
|
41
|
+
</div>
|
|
42
|
+
<div className="content-background space-between">
|
|
43
|
+
<small>Unbonded Tokens</small>
|
|
44
|
+
<p>{pool ? pool.not_bonded_tokens : '---'} SEI</p>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
<div className="card-footer">
|
|
48
|
+
<button onClick={getStakingPool}>Fetch Staking Data</button>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getBalanceStargate = async () => {
|
|
55
|
+
if (!address) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const queryClient = await getStargateClient(defaultUrls[chainId].rpc);
|
|
59
|
+
const useiBalance = await queryClient.getBalance(address, 'usei');
|
|
60
|
+
const seiBalance = Number(useiBalance.amount) / 1000000;
|
|
61
|
+
setBalance(seiBalance);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const renderBalanceExample = () => {
|
|
65
|
+
return (
|
|
66
|
+
<div className="card">
|
|
67
|
+
<div className="card-header">
|
|
68
|
+
<p className="card__title">Wallet Balance</p>
|
|
69
|
+
<small className="card__description">
|
|
70
|
+
<a href="https://cosmos.github.io/cosmjs/latest/stargate/classes/StargateClient.html" target="_blank">
|
|
71
|
+
Stargate Client
|
|
72
|
+
</a>{' '}
|
|
73
|
+
query example
|
|
74
|
+
</small>
|
|
75
|
+
</div>
|
|
76
|
+
<div className="card-body">
|
|
77
|
+
<div className="content-background space-between">
|
|
78
|
+
<small>SEI</small>
|
|
79
|
+
<p>{balance ? balance : '---'} SEI</p>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
<div className="card-footer">
|
|
83
|
+
<button onClick={getBalanceStargate}>Fetch balance</button>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const fetchCount = async () => {
|
|
90
|
+
const cosmWasmClient = await getCosmWasmClient(defaultUrls[chainId].rpc);
|
|
91
|
+
console.log(cosmWasmClient);
|
|
92
|
+
const CONTRACT_ADDRESS = 'sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m';
|
|
93
|
+
const response = await cosmWasmClient.queryContractSmart(CONTRACT_ADDRESS, {
|
|
94
|
+
get_count: {}
|
|
95
|
+
});
|
|
96
|
+
const result = response?.count;
|
|
97
|
+
if (result) {
|
|
98
|
+
setCount(result);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const incrementCounter = async () => {
|
|
103
|
+
if (!address) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const offlineSigner = await getOfflineSignerAmino();
|
|
107
|
+
const signingCosmWasmClient = await getSigningCosmWasmClient(defaultUrls[chainId].rpc, offlineSigner);
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const senderAddress = address;
|
|
111
|
+
const CONTRACT_ADDRESS = 'sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m';
|
|
112
|
+
|
|
113
|
+
// Build message content
|
|
114
|
+
const msg = { increment: {} };
|
|
115
|
+
|
|
116
|
+
// Define gas price and limit
|
|
117
|
+
const fee = {
|
|
118
|
+
amount: [{ amount: '20000', denom: 'usei' }],
|
|
119
|
+
gas: '200000'
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Call smart contract execute msg
|
|
123
|
+
await signingCosmWasmClient?.execute(senderAddress, CONTRACT_ADDRESS, msg, fee);
|
|
124
|
+
|
|
125
|
+
await fetchCount();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.log(error);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const renderCounterContractExample = () => {
|
|
132
|
+
return (
|
|
133
|
+
<div className="card">
|
|
134
|
+
<div className="card-header">
|
|
135
|
+
<p className="card__title">Smart contract interaction</p>
|
|
136
|
+
<small>
|
|
137
|
+
<a href="https://cosmos.github.io/cosmjs/latest/cosmwasm-stargate/classes/SigningCosmWasmClient.html" target="_blank">
|
|
138
|
+
CosmWasm Clients
|
|
139
|
+
</a>{' '}
|
|
140
|
+
example of smart contract interaction
|
|
141
|
+
</small>
|
|
142
|
+
</div>
|
|
143
|
+
<div className="card-body">
|
|
144
|
+
<div className="content-background space-between">
|
|
145
|
+
<small>Count</small>
|
|
146
|
+
<p>{count}</p>
|
|
147
|
+
<button className="small outline" onClick={incrementCounter}>
|
|
148
|
+
Increase
|
|
149
|
+
</button>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
<div className="card-footer">
|
|
153
|
+
<button onClick={fetchCount}>Fetch count</button>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div className="grid">
|
|
161
|
+
{renderBalanceExample()}
|
|
162
|
+
{renderStakingPoolExample()}
|
|
163
|
+
{renderCounterContractExample()}
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
175
166
|
}
|
|
176
167
|
|
|
177
|
-
export default Examples;
|
|
168
|
+
export default Examples;
|