@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.
Files changed (127) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +16 -25
  3. package/biome.json +8 -0
  4. package/dist/main.js +12 -11
  5. package/dist/templates/next-cosmos-template/.eslintrc.json +1 -1
  6. package/dist/templates/next-cosmos-template/next.config.mjs +9 -9
  7. package/dist/templates/next-cosmos-template/package.json +29 -29
  8. package/dist/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +162 -171
  9. package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +92 -94
  10. package/dist/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +22 -49
  11. package/dist/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
  12. package/dist/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +13 -17
  13. package/dist/templates/next-cosmos-template/src/app/components/index.ts +3 -3
  14. package/dist/templates/next-cosmos-template/src/app/constants/chain.ts +9 -9
  15. package/dist/templates/next-cosmos-template/src/app/constants/index.ts +1 -1
  16. package/dist/templates/next-cosmos-template/src/app/index.css +99 -86
  17. package/dist/templates/next-cosmos-template/src/app/layout.tsx +12 -12
  18. package/dist/templates/next-cosmos-template/src/app/page.tsx +13 -13
  19. package/dist/templates/next-cosmos-template/tsconfig.json +24 -24
  20. package/dist/templates/next-wagmi-template/.eslintrc.json +1 -1
  21. package/dist/templates/next-wagmi-template/package.json +28 -28
  22. package/dist/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +223 -237
  23. package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +92 -94
  24. package/dist/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +10 -36
  25. package/dist/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +29 -28
  26. package/dist/templates/next-wagmi-template/src/app/components/index.ts +2 -2
  27. package/dist/templates/next-wagmi-template/src/app/constants/chain.ts +2 -2
  28. package/dist/templates/next-wagmi-template/src/app/constants/index.ts +1 -1
  29. package/dist/templates/next-wagmi-template/src/app/index.css +99 -86
  30. package/dist/templates/next-wagmi-template/src/app/layout.tsx +12 -12
  31. package/dist/templates/next-wagmi-template/src/app/page.tsx +17 -17
  32. package/dist/templates/next-wagmi-template/tsconfig.json +24 -24
  33. package/dist/templates/vite-cosmos-template/.eslintrc.cjs +10 -17
  34. package/dist/templates/vite-cosmos-template/package.json +33 -33
  35. package/dist/templates/vite-cosmos-template/src/App.tsx +11 -12
  36. package/dist/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +162 -171
  37. package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +92 -94
  38. package/dist/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +20 -45
  39. package/dist/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
  40. package/dist/templates/vite-cosmos-template/src/components/Web3Provider.tsx +14 -18
  41. package/dist/templates/vite-cosmos-template/src/components/index.ts +4 -4
  42. package/dist/templates/vite-cosmos-template/src/constants/chain.ts +9 -9
  43. package/dist/templates/vite-cosmos-template/src/constants/index.ts +1 -1
  44. package/dist/templates/vite-cosmos-template/src/index.css +99 -86
  45. package/dist/templates/vite-cosmos-template/src/main.tsx +10 -10
  46. package/dist/templates/vite-cosmos-template/tsconfig.app.json +21 -23
  47. package/dist/templates/vite-cosmos-template/tsconfig.json +9 -9
  48. package/dist/templates/vite-cosmos-template/tsconfig.node.json +11 -11
  49. package/dist/templates/vite-cosmos-template/vite.config.ts +4 -4
  50. package/dist/templates/vite-wagmi-template/.eslintrc.cjs +10 -17
  51. package/dist/templates/vite-wagmi-template/package.json +31 -31
  52. package/dist/templates/vite-wagmi-template/src/App.tsx +12 -13
  53. package/dist/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +225 -239
  54. package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +92 -94
  55. package/dist/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +28 -53
  56. package/dist/templates/vite-wagmi-template/src/components/Web3Provider.tsx +29 -28
  57. package/dist/templates/vite-wagmi-template/src/constants/chain.ts +1 -1
  58. package/dist/templates/vite-wagmi-template/src/constants/index.ts +1 -1
  59. package/dist/templates/vite-wagmi-template/src/index.css +98 -85
  60. package/dist/templates/vite-wagmi-template/src/main.tsx +10 -10
  61. package/dist/templates/vite-wagmi-template/tsconfig.app.json +21 -23
  62. package/dist/templates/vite-wagmi-template/tsconfig.json +9 -9
  63. package/dist/templates/vite-wagmi-template/tsconfig.node.json +11 -11
  64. package/dist/templates/vite-wagmi-template/vite.config.ts +7 -7
  65. package/package.json +3 -2
  66. package/src/main.ts +31 -33
  67. package/templates/next-cosmos-template/.eslintrc.json +1 -1
  68. package/templates/next-cosmos-template/next.config.mjs +9 -9
  69. package/templates/next-cosmos-template/package.json +29 -29
  70. package/templates/next-cosmos-template/src/app/components/Homepage/Examples.tsx +162 -171
  71. package/templates/next-cosmos-template/src/app/components/Homepage/Homepage.css +92 -94
  72. package/templates/next-cosmos-template/src/app/components/Homepage/Homepage.tsx +22 -49
  73. package/templates/next-cosmos-template/src/app/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
  74. package/templates/next-cosmos-template/src/app/components/Web3Provider.tsx +13 -17
  75. package/templates/next-cosmos-template/src/app/components/index.ts +3 -3
  76. package/templates/next-cosmos-template/src/app/constants/chain.ts +9 -9
  77. package/templates/next-cosmos-template/src/app/constants/index.ts +1 -1
  78. package/templates/next-cosmos-template/src/app/index.css +99 -86
  79. package/templates/next-cosmos-template/src/app/layout.tsx +12 -12
  80. package/templates/next-cosmos-template/src/app/page.tsx +13 -13
  81. package/templates/next-cosmos-template/tsconfig.json +24 -24
  82. package/templates/next-wagmi-template/.eslintrc.json +1 -1
  83. package/templates/next-wagmi-template/package.json +28 -28
  84. package/templates/next-wagmi-template/src/app/components/Homepage/Examples.tsx +223 -237
  85. package/templates/next-wagmi-template/src/app/components/Homepage/Homepage.css +92 -94
  86. package/templates/next-wagmi-template/src/app/components/Homepage/Homepage.tsx +10 -36
  87. package/templates/next-wagmi-template/src/app/components/Web3Provider.tsx +29 -28
  88. package/templates/next-wagmi-template/src/app/components/index.ts +2 -2
  89. package/templates/next-wagmi-template/src/app/constants/chain.ts +2 -2
  90. package/templates/next-wagmi-template/src/app/constants/index.ts +1 -1
  91. package/templates/next-wagmi-template/src/app/index.css +99 -86
  92. package/templates/next-wagmi-template/src/app/layout.tsx +12 -12
  93. package/templates/next-wagmi-template/src/app/page.tsx +17 -17
  94. package/templates/next-wagmi-template/tsconfig.json +24 -24
  95. package/templates/vite-cosmos-template/.eslintrc.cjs +10 -17
  96. package/templates/vite-cosmos-template/package.json +33 -33
  97. package/templates/vite-cosmos-template/src/App.tsx +11 -12
  98. package/templates/vite-cosmos-template/src/components/Homepage/Examples.tsx +162 -171
  99. package/templates/vite-cosmos-template/src/components/Homepage/Homepage.css +92 -94
  100. package/templates/vite-cosmos-template/src/components/Homepage/Homepage.tsx +20 -45
  101. package/templates/vite-cosmos-template/src/components/WalletConnectButton/WalletConnectButton.tsx +11 -19
  102. package/templates/vite-cosmos-template/src/components/Web3Provider.tsx +14 -18
  103. package/templates/vite-cosmos-template/src/components/index.ts +4 -4
  104. package/templates/vite-cosmos-template/src/constants/chain.ts +9 -9
  105. package/templates/vite-cosmos-template/src/constants/index.ts +1 -1
  106. package/templates/vite-cosmos-template/src/index.css +99 -86
  107. package/templates/vite-cosmos-template/src/main.tsx +10 -10
  108. package/templates/vite-cosmos-template/tsconfig.app.json +21 -23
  109. package/templates/vite-cosmos-template/tsconfig.json +9 -9
  110. package/templates/vite-cosmos-template/tsconfig.node.json +11 -11
  111. package/templates/vite-cosmos-template/vite.config.ts +4 -4
  112. package/templates/vite-wagmi-template/.eslintrc.cjs +10 -17
  113. package/templates/vite-wagmi-template/package.json +31 -31
  114. package/templates/vite-wagmi-template/src/App.tsx +12 -13
  115. package/templates/vite-wagmi-template/src/components/Homepage/Examples.tsx +225 -239
  116. package/templates/vite-wagmi-template/src/components/Homepage/Homepage.css +92 -94
  117. package/templates/vite-wagmi-template/src/components/Homepage/Homepage.tsx +28 -53
  118. package/templates/vite-wagmi-template/src/components/Web3Provider.tsx +29 -28
  119. package/templates/vite-wagmi-template/src/constants/chain.ts +1 -1
  120. package/templates/vite-wagmi-template/src/constants/index.ts +1 -1
  121. package/templates/vite-wagmi-template/src/index.css +98 -85
  122. package/templates/vite-wagmi-template/src/main.tsx +10 -10
  123. package/templates/vite-wagmi-template/tsconfig.app.json +21 -23
  124. package/templates/vite-wagmi-template/tsconfig.json +9 -9
  125. package/templates/vite-wagmi-template/tsconfig.node.json +11 -11
  126. package/templates/vite-wagmi-template/vite.config.ts +7 -7
  127. package/tsconfig.json +24 -28
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @sei-js/create-sei-app
2
2
 
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - a64da08: Update README files in NPM
8
+
3
9
  ## 0.0.2
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,36 +1,27 @@
1
- # Create Sei App
1
+ <div align="center">
2
2
 
3
- This repository contains various templates for kick-starting a Sei application out of the box, as well as a CLI (Command Line Interface) tool that can be used to create projects using the given templates.
3
+ # @sei-js/create-sei
4
4
 
5
- You can use either:
6
- - Next.js
7
- - Vite.js
5
+ [![npm version](https://badge.fury.io/js/@sei-js%2Fcreate-sei.svg)](https://badge.fury.io/js/@sei-js%2Fcreate-sei)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
8
+ [![Sei Network](https://img.shields.io/badge/Sei-Network-red)](https://sei.io)
8
9
 
9
- to scaffold your project.
10
+ **Scaffold new Sei applications with pre-configured templates and tooling**
10
11
 
11
- ## Scaffold your project
12
- Simply run `npx @sei-js/create-sei app` to run the setup wizard and choose the template you want to use.
12
+ [Documentation](https://sei-js.docs.sei.io/create-sei/welcome) • [GitHub](https://github.com/sei-protocol/sei-js) • [NPM](https://www.npmjs.com/package/@sei-js/create-sei) • [Telegram](https://t.me/+LPW_1djQwRQwMzlk)
13
13
 
14
- ## EVM Applications (Recommended)
15
- Building on our EVM (Ethereum Virtual Machine) is the easiest way to get your dApp kick-started on Sei! The mature EVM ecosystem provides many tools out of the box to help developers build faster, including deploying smart contracts and other helpful connection libraries.
14
+ </div>
16
15
 
17
- This tool will offer multiple variants of EVM tooling, including
18
- - [Wagmi](https://wagmi.sh/core/getting-started) ([Viem](https://viem.sh/)): Recommended
19
- - [Ethers](https://docs.ethers.org/v6/)
16
+ ## 🚀 Quick Start
20
17
 
21
- Both variants use [@sei-js/evm](https://sei-protocol.github.io/sei-js/modules/evm.html)
18
+ ```bash
19
+ npx @sei-js/create-sei app -n my-sei-app
20
+ ```
22
21
 
23
- If you are new to Web3 development, we recommend using Wagmi since it provides helpful hooks out of the box.
22
+ ## 📚 Documentation
24
23
 
25
- ## Cosmos Applications
26
- Cosmos based Sei Applications interact with the CosmWasm VM on the chain. Use this if you are a seasoned CosmWasm developer, or if you intend to interact with CosmWasm Smart Contracts, as well as other chains in the Cosmos ecosystem.
24
+ For complete documentation, examples, and guides, visit:
25
+ **[sei-js.docs.sei.io/create-sei](https://sei-js.docs.sei.io/create-sei/welcome)**
27
26
 
28
- If you think your app might require interaction with native Cosmos modules, you should check the list of [precompiles](https://www.docs.sei.io/dev-interoperability/precompiles/addr) to determine if the same support can be offered by the EVM.
29
27
 
30
- Cosmos Applications use
31
- - [CosmosKit](https://cosmology.zone/products/cosmos-kit)
32
- - [@sei-js/cosmjs](https://sei-protocol.github.io/sei-js/modules/cosmjs.html)
33
- - [Cosmjs](https://github.com/cosmos/cosmjs)
34
-
35
- ## Contributing
36
- We love contributions from the amazing Sei community! If you have a dApp template to contribute, do make a Pull Request into the [sei-js](https://github.com/sei-protocol/sei-js) repository.
package/biome.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3
+ "extends": ["../../biome.json"],
4
+ "files": {
5
+ "ignoreUnknown": false,
6
+ "ignore": ["templates/**"]
7
+ }
8
+ }
package/dist/main.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import inquirer from 'inquirer';
3
2
  import boxen from 'boxen';
4
- import path from 'path';
5
- import fs from 'fs';
6
- import { fileURLToPath } from 'url';
7
- import { dirname } from 'path';
3
+ import inquirer from 'inquirer';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { dirname } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
8
  import { Command } from 'commander';
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
@@ -66,13 +66,14 @@ const promptEVMLibrary = async () => {
66
66
  return evmLibrary;
67
67
  };
68
68
  function isValidDirectoryName(dirName) {
69
- const illegalRe = /[<>:"/\\|?*\x00-\x1F]/g;
69
+ const illegalRe = /[<>:"/\\|?*]/g;
70
70
  const windowsReservedRe = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
71
71
  const trailingRe = /[. ]+$/;
72
72
  const validNpmPackageRe = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*)?[a-z0-9-~][a-z0-9-._~]*$/;
73
73
  if (typeof dirName !== 'string' || dirName.length === 0) {
74
74
  return false;
75
75
  }
76
+ // Check for illegal characters, Windows reserved names, trailing spaces/dots
76
77
  if (illegalRe.test(dirName) || windowsReservedRe.test(dirName) || trailingRe.test(dirName) || !validNpmPackageRe.test(dirName)) {
77
78
  return false;
78
79
  }
@@ -131,10 +132,10 @@ async function runWizard(options) {
131
132
  ]);
132
133
  dAppName = promptResult.dAppName;
133
134
  }
134
- const appFramework = options.framework || await promptFramework();
135
- let appConnectionType = options.ecosystem || await promptRpcIntegrations();
136
- if (appConnectionType == RPCIntegrationType.EVM) {
137
- appConnectionType = options.library || await promptEVMLibrary();
135
+ const appFramework = options.framework || (await promptFramework());
136
+ let appConnectionType = options.ecosystem || (await promptRpcIntegrations());
137
+ if (appConnectionType === RPCIntegrationType.EVM) {
138
+ appConnectionType = options.library || (await promptEVMLibrary());
138
139
  }
139
140
  const templateName = `${appFramework}-${appConnectionType}-template`;
140
141
  const templatePath = path.join(__dirname, 'templates', templateName);
@@ -146,7 +147,7 @@ async function runWizard(options) {
146
147
  program
147
148
  .command('app')
148
149
  .description('Create a new SEI dApp')
149
- .option('-n, --name <name>', `Specify the name of your dApp. Name must be a valid package name.`)
150
+ .option('-n, --name <name>', 'Specify the name of your dApp. Name must be a valid package name.')
150
151
  .option('-f, --framework <framework>', `Specify the app framework to use: [${Object.values(FrontendScaffolding).join(', ')}]`)
151
152
  .option('-e, --ecosystem <ecosystem>', `Specify the ecosystem to use: [${Object.values(RPCIntegrationType).join(', ')}]`)
152
153
  .option('-l, --library <library>', `Specify the EVM library to use: [${Object.values(EVMLibrary).join(', ')}]. Only used if ecosystem chosen is 'EVM'`)
@@ -1,3 +1,3 @@
1
1
  {
2
- "extends": "next/core-web-vitals"
2
+ "extends": "next/core-web-vitals"
3
3
  }
@@ -1,14 +1,14 @@
1
1
  /** @type {import('next').NextConfig} */
2
2
  const nextConfig = {
3
- images: {
4
- remotePatterns: [
5
- {
6
- protocol: 'https',
7
- hostname: 'cdn.sei.io',
8
- port: '',
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
- "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
- }
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 "@sei-js/cosmjs";
2
- import { useState } from "react";
3
- import { defaultUrls, selectedChain } from "../../constants";
4
- import { useChain } from "@cosmos-kit/react";
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
- chainId: string
9
- }
8
+ chainId: string;
9
+ };
10
10
 
11
11
  function Examples({ chainId }: ExampleProps) {
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
32
- href="https://sei-protocol.github.io/sei-js/functions/cosmjs.getQueryClient.html"
33
- target="_blank">Sei QueryClient</a> query example
34
- </small>
35
- </div>
36
- <div className="card-body">
37
- <div className="content-background space-between">
38
- <small>Bonded Tokens</small>
39
- <p>{pool ? pool.bonded_tokens : '---'} SEI</p>
40
- </div>
41
- <div className="content-background space-between">
42
- <small>Unbonded Tokens</small>
43
- <p>{pool ? pool.not_bonded_tokens : '---'} SEI</p>
44
- </div>
45
- </div>
46
- <div className="card-footer">
47
- <button onClick={getStakingPool}>Fetch Staking Data</button>
48
- </div>
49
- </div>
50
- )
51
- }
52
-
53
- const getBalanceStargate = async () => {
54
- if (!address) {
55
- return undefined
56
- }
57
- const queryClient = await getStargateClient(defaultUrls[chainId].rpc);
58
- const useiBalance = await queryClient.getBalance(address, 'usei');
59
- const seiBalance = Number(useiBalance.amount) / 1000000
60
- setBalance(seiBalance);
61
- }
62
-
63
- const renderBalanceExample = () => {
64
- return (
65
- <div className="card">
66
- <div className="card-header">
67
- <p className="card__title">Wallet Balance</p>
68
- <small className="card__description">
69
- <a
70
- href="https://cosmos.github.io/cosmjs/latest/stargate/classes/StargateClient.html"
71
- target="_blank">Stargate Client</a> query example
72
- </small>
73
- </div>
74
- <div className="card-body">
75
- <div className="content-background space-between">
76
- <small>SEI</small>
77
- <p>{balance ? balance : '---' } SEI</p>
78
- </div>
79
- </div>
80
- <div className="card-footer">
81
- <button onClick={getBalanceStargate}>Fetch balance</button>
82
- </div>
83
- </div>
84
- )
85
- }
86
-
87
- const fetchCount = async () => {
88
- const cosmWasmClient = await getCosmWasmClient(defaultUrls[chainId].rpc);
89
- console.log(cosmWasmClient);
90
- const CONTRACT_ADDRESS =
91
- "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m";
92
- const response = await cosmWasmClient.queryContractSmart(CONTRACT_ADDRESS, {
93
- get_count: {},
94
- });
95
- const result = response?.count;
96
- if (result) {
97
- setCount(result);
98
- }
99
- }
100
-
101
- const incrementCounter = async () => {
102
- if (!address) {
103
- return;
104
- }
105
- const offlineSigner = await getOfflineSignerAmino();
106
- const signingCosmWasmClient = await getSigningCosmWasmClient(
107
- defaultUrls[chainId].rpc,
108
- offlineSigner
109
- )
110
-
111
- try {
112
- const senderAddress = address;
113
- const CONTRACT_ADDRESS =
114
- "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m";
115
-
116
- // Build message content
117
- const msg = { increment: {} };
118
-
119
- // Define gas price and limit
120
- const fee = {
121
- amount: [{ amount: "20000", denom: "usei" }],
122
- gas: "200000",
123
- };
124
-
125
- // Call smart contract execute msg
126
- await signingCosmWasmClient?.execute(senderAddress, CONTRACT_ADDRESS, msg, fee);
127
-
128
- await fetchCount();
129
-
130
- } catch (error) {
131
- console.log(error)
132
- }
133
- };
134
-
135
- const renderCounterContractExample = () => {
136
- return (
137
- <div className="card">
138
- <div className="card-header">
139
- <p className="card__title">Smart contract interaction</p>
140
- <small>
141
- <a
142
- href="https://cosmos.github.io/cosmjs/latest/cosmwasm-stargate/classes/SigningCosmWasmClient.html"
143
- target="_blank">
144
- CosmWasm Clients
145
- </a> example of smart
146
- contract interaction
147
- </small>
148
- </div>
149
- <div className="card-body">
150
- <div className="content-background space-between">
151
- <small>Count</small>
152
- <p>{count}</p>
153
- <button
154
- className="small outline"
155
- onClick={incrementCounter}
156
- >
157
- Increase
158
- </button>
159
- </div>
160
- </div>
161
- <div className="card-footer">
162
- <button onClick={fetchCount}>Fetch count</button>
163
- </div>
164
- </div>
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;