create-sbc-app 0.2.0 → 0.3.0
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/README.md +15 -9
- package/bin/cli.js +33 -2
- package/package.json +1 -1
- package/templates/README.md +11 -2
- package/templates/react/.env.template +2 -1
- package/templates/react/src/App.tsx.template +94 -10
- package/templates/react-dynamic/.env.template +2 -2
- package/templates/react-dynamic/src/App.tsx.template +40 -18
- package/templates/react-para/.env.template +2 -2
- package/templates/react-para/src/App.tsx.template +44 -16
- package/templates/react-para/vite.config.ts.template +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ pnpm dev # or npm run dev
|
|
|
24
24
|
## CLI Options
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
Usage: create-sbc-app [project-directory] [options]
|
|
27
|
+
Usage: npx create-sbc-app [project-directory] [options]
|
|
28
28
|
|
|
29
29
|
Create a new SBC App Kit project with an opinionated template
|
|
30
30
|
|
|
@@ -34,21 +34,26 @@ Arguments:
|
|
|
34
34
|
Options:
|
|
35
35
|
-V, --version output the version number
|
|
36
36
|
-t, --template <type> Template to use: react, react-dynamic, or react-para
|
|
37
|
+
-c, --chain <chain> Chain to use: baseSepolia, base, or radiusTestnet
|
|
37
38
|
--api-key <apiKey> Your SBC API key for immediate configuration
|
|
38
39
|
--wallet <wallet> Wallet integration (not yet implemented)
|
|
39
40
|
-h, --help display help for command
|
|
40
41
|
|
|
41
42
|
Examples:
|
|
42
|
-
$ create-sbc-app my-app
|
|
43
|
-
$ create-sbc-app my-app --template react
|
|
44
|
-
$ create-sbc-app my-app --template react-dynamic
|
|
45
|
-
$ create-sbc-app my-app --template react-para
|
|
46
|
-
# Next.js template removed for now
|
|
43
|
+
$ npx create-sbc-app my-app
|
|
44
|
+
$ npx create-sbc-app my-app --template react --chain radiusTestnet
|
|
45
|
+
$ npx create-sbc-app my-app --template react-dynamic --chain base
|
|
46
|
+
$ npx create-sbc-app my-app --template react-para --api-key your-key
|
|
47
47
|
|
|
48
48
|
Available Templates:
|
|
49
49
|
- react React + Vite template with SBC integration
|
|
50
50
|
- react-dynamic React + Vite with Dynamic wallet integration
|
|
51
51
|
- react-para React + Vite with Para wallet integration
|
|
52
|
+
|
|
53
|
+
Available Chains:
|
|
54
|
+
- baseSepolia Base Sepolia testnet (default)
|
|
55
|
+
- base Base mainnet
|
|
56
|
+
- radiusTestnet Radius testnet
|
|
52
57
|
```
|
|
53
58
|
|
|
54
59
|
## ✨ Features
|
|
@@ -108,7 +113,8 @@ The template includes comprehensive environment configuration:
|
|
|
108
113
|
```bash
|
|
109
114
|
# Your SBC API key (get from SBC dashboard)
|
|
110
115
|
VITE_SBC_API_KEY=your_api_key_here
|
|
111
|
-
|
|
116
|
+
|
|
117
|
+
# Supported chains: "baseSepolia" | "base" | "radiusTestnet"
|
|
112
118
|
VITE_CHAIN="baseSepolia"
|
|
113
119
|
```
|
|
114
120
|
|
|
@@ -139,8 +145,8 @@ cp .env.template .env
|
|
|
139
145
|
|
|
140
146
|
# then ensure your .env has the environment variables set up
|
|
141
147
|
|
|
142
|
-
# "base"
|
|
143
|
-
VITE_CHAIN="baseSepolia"
|
|
148
|
+
# Supported chains: "baseSepolia" | "base" | "radiusTestnet"
|
|
149
|
+
VITE_CHAIN="baseSepolia"
|
|
144
150
|
# Custom RPC URL (optional) - e.g. get one from Alchemey at https://dashboard.alchemy.com/apps
|
|
145
151
|
VITE_RPC_URL=
|
|
146
152
|
# Get your SBC API Key at https://dashboard.stablecoin.xyz
|
package/bin/cli.js
CHANGED
|
@@ -13,18 +13,24 @@ program
|
|
|
13
13
|
.version('0.2.0')
|
|
14
14
|
.argument('[project-directory]', 'Directory to create the new app in')
|
|
15
15
|
.option('-t, --template <template>', 'Template to use: react, react-dynamic, or react-para')
|
|
16
|
+
.option('-c, --chain <chain>', 'Chain to use: baseSepolia, base, or radiusTestnet')
|
|
16
17
|
.option('--api-key <apiKey>', 'Your SBC API key for immediate configuration')
|
|
17
18
|
.option('--wallet <wallet>', 'Wallet integration (not yet implemented)')
|
|
18
19
|
.addHelpText('after', `
|
|
19
20
|
Examples:
|
|
20
21
|
$ create-sbc-app my-app
|
|
21
|
-
$ create-sbc-app my-app --template react
|
|
22
|
+
$ create-sbc-app my-app --template react --chain radiusTestnet
|
|
22
23
|
$ create-sbc-app my-app --template react --api-key your-api-key
|
|
23
24
|
|
|
24
25
|
Available Templates:
|
|
25
26
|
- react React + Vite template with SBC integration
|
|
26
27
|
- react-dynamic React + Vite with Dynamic wallet integration
|
|
27
28
|
- react-para React + Vite with Para wallet integration
|
|
29
|
+
|
|
30
|
+
Available Chains:
|
|
31
|
+
- baseSepolia Base Sepolia testnet (default)
|
|
32
|
+
- base Base mainnet
|
|
33
|
+
- radiusTestnet Radius testnet
|
|
28
34
|
`)
|
|
29
35
|
.action(async (dir, options) => {
|
|
30
36
|
if (options.wallet) {
|
|
@@ -36,6 +42,11 @@ Available Templates:
|
|
|
36
42
|
{ title: 'React (Dynamic wallet)', value: 'react-dynamic' },
|
|
37
43
|
{ title: 'React (Para wallet)', value: 'react-para' }
|
|
38
44
|
];
|
|
45
|
+
const chainChoices = [
|
|
46
|
+
{ title: 'Base Sepolia (testnet)', value: 'baseSepolia' },
|
|
47
|
+
{ title: 'Base (mainnet)', value: 'base' },
|
|
48
|
+
{ title: 'Radius Testnet', value: 'radiusTestnet' }
|
|
49
|
+
];
|
|
39
50
|
// Use provided argument or prompt for project directory
|
|
40
51
|
let projectDir = dir && dir.trim() ? dir.trim() : '';
|
|
41
52
|
if (!projectDir) {
|
|
@@ -69,6 +80,26 @@ Available Templates:
|
|
|
69
80
|
process.exit(1);
|
|
70
81
|
}
|
|
71
82
|
}
|
|
83
|
+
// Use provided option or prompt for chain
|
|
84
|
+
let chain = options.chain && ['baseSepolia', 'base', 'radiusTestnet'].includes(options.chain) ? options.chain : '';
|
|
85
|
+
if (!chain) {
|
|
86
|
+
const res = await prompts({
|
|
87
|
+
type: 'select',
|
|
88
|
+
name: 'chain',
|
|
89
|
+
message: 'Which chain?',
|
|
90
|
+
choices: chainChoices,
|
|
91
|
+
initial: 0
|
|
92
|
+
});
|
|
93
|
+
if (res.chain === undefined) {
|
|
94
|
+
console.log('Chain selection is required.');
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
chain = res.chain;
|
|
98
|
+
if (!chain || !['baseSepolia', 'base', 'radiusTestnet'].includes(chain)) {
|
|
99
|
+
console.log('Chain selection is required.');
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
72
103
|
// Use provided option or prompt for API key
|
|
73
104
|
let apiKey = options.apiKey && options.apiKey.trim() ? options.apiKey.trim() : '';
|
|
74
105
|
if (!apiKey) {
|
|
@@ -96,7 +127,7 @@ Available Templates:
|
|
|
96
127
|
}
|
|
97
128
|
await copyTemplate(templateDir, targetDir, {
|
|
98
129
|
projectName: projectDir,
|
|
99
|
-
chain:
|
|
130
|
+
chain: chain,
|
|
100
131
|
apiKey: apiKey
|
|
101
132
|
});
|
|
102
133
|
// Ensure SBC logo exists in public/ for all templates
|
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -5,13 +5,22 @@ This directory contains ready-to-use templates for quickly starting new projects
|
|
|
5
5
|
## Available Templates
|
|
6
6
|
|
|
7
7
|
- **react/** – Minimal React app with SBC integration (Vite)
|
|
8
|
+
- **react-dynamic/** – React + Dynamic wallet + SBC App Kit (Vite)
|
|
9
|
+
- **react-para/** – React + Para wallet + SBC App Kit (Vite)
|
|
8
10
|
|
|
9
11
|
## How to Use a Template
|
|
10
12
|
|
|
11
13
|
1. **Copy the template directory** you want to use:
|
|
12
14
|
|
|
13
15
|
```bash
|
|
16
|
+
# Plain React template
|
|
14
17
|
cp -r create-sbc-app/react my-new-sbc-app
|
|
18
|
+
|
|
19
|
+
# Dynamic wallet template
|
|
20
|
+
cp -r create-sbc-app/react-dynamic my-dynamic-app
|
|
21
|
+
|
|
22
|
+
# Para wallet template
|
|
23
|
+
cp -r create-sbc-app/react-para my-para-app
|
|
15
24
|
```
|
|
16
25
|
|
|
17
26
|
2. **Install dependencies:**
|
|
@@ -32,8 +41,8 @@ This directory contains ready-to-use templates for quickly starting new projects
|
|
|
32
41
|
```
|
|
33
42
|
|
|
34
43
|
4. **Customize as needed:**
|
|
35
|
-
- Update the API key and config in `src/App.tsx
|
|
36
|
-
- Follow
|
|
44
|
+
- Update the API key and config in `src/App.tsx`.
|
|
45
|
+
- Follow each template’s README for specific details and environment variables.
|
|
37
46
|
|
|
38
47
|
## Keeping Templates Up to Date
|
|
39
48
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# SBC App Kit Configuration
|
|
2
|
-
|
|
2
|
+
# Supported chains: "baseSepolia" | "base" | "radiusTestnet"
|
|
3
|
+
VITE_CHAIN="{{chain}}"
|
|
3
4
|
# Custom RPC URL (optional) - e.g. get one from Alchemey at https://dashboard.alchemy.com/apps
|
|
4
5
|
VITE_RPC_URL=
|
|
5
6
|
# Get your SBC API Key at https://dashboard.stablecoin.xyz
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
import { useState, useEffect, useRef, createContext, useContext } from 'react';
|
|
2
2
|
import { SbcProvider, WalletButton, useSbcApp, useUserOperation } from '@stablecoin.xyz/react';
|
|
3
|
+
import { radiusTestnet, TestSBC_CONTRACT_ADDRESS } from '@stablecoin.xyz/core';
|
|
3
4
|
import { base, baseSepolia } from 'viem/chains';
|
|
4
5
|
import { createPublicClient, http, getAddress, parseSignature, WalletClient, PublicClient } from 'viem';
|
|
5
6
|
import { parseUnits, encodeFunctionData, erc20Abi } from 'viem';
|
|
6
7
|
import './App.css';
|
|
7
8
|
|
|
8
9
|
// Chain selection helpers
|
|
9
|
-
const
|
|
10
|
+
const getChain = () => {
|
|
11
|
+
const chainEnv = import.meta.env.VITE_CHAIN;
|
|
12
|
+
if (chainEnv === 'base') return base;
|
|
13
|
+
if (chainEnv === 'radiusTestnet') return radiusTestnet;
|
|
14
|
+
return baseSepolia;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const chain = getChain();
|
|
10
18
|
const rpcUrl = import.meta.env.VITE_RPC_URL;
|
|
11
19
|
|
|
20
|
+
// Radius testnet uses TestSBC (a test token for development)
|
|
21
|
+
const TEST_SBC_DECIMALS = 6;
|
|
22
|
+
|
|
12
23
|
const SBC_TOKEN_ADDRESS = (chain) => {
|
|
13
24
|
if (chain.id === baseSepolia.id) {
|
|
14
25
|
return '0xf9FB20B8E097904f0aB7d12e9DbeE88f2dcd0F16';
|
|
15
26
|
} else if (chain.id === base.id) {
|
|
16
27
|
return '0xfdcC3dd6671eaB0709A4C0f3F53De9a333d80798';
|
|
28
|
+
} else if (chain.id === radiusTestnet.id) {
|
|
29
|
+
return TestSBC_CONTRACT_ADDRESS;
|
|
17
30
|
}
|
|
18
31
|
throw new Error('Unsupported chain');
|
|
19
32
|
};
|
|
@@ -23,15 +36,26 @@ const SBC_DECIMALS = (chain) => {
|
|
|
23
36
|
return 6;
|
|
24
37
|
} else if (chain.id === base.id) {
|
|
25
38
|
return 18;
|
|
39
|
+
} else if (chain.id === radiusTestnet.id) {
|
|
40
|
+
return TEST_SBC_DECIMALS;
|
|
26
41
|
}
|
|
27
42
|
throw new Error('Unsupported chain');
|
|
28
43
|
};
|
|
29
44
|
|
|
45
|
+
const getTokenSymbol = (chain) => {
|
|
46
|
+
if (chain.id === radiusTestnet.id) {
|
|
47
|
+
return 'TestSBC';
|
|
48
|
+
}
|
|
49
|
+
return 'SBC';
|
|
50
|
+
};
|
|
51
|
+
|
|
30
52
|
const chainExplorer = (chain) => {
|
|
31
53
|
if (chain.id === baseSepolia.id) {
|
|
32
54
|
return 'https://sepolia.basescan.org';
|
|
33
55
|
} else if (chain.id === base.id) {
|
|
34
56
|
return 'https://basescan.org';
|
|
57
|
+
} else if (chain.id === radiusTestnet.id) {
|
|
58
|
+
return 'https://testnet.radiustech.xyz/testnet/explorer';
|
|
35
59
|
}
|
|
36
60
|
throw new Error('Unsupported chain');
|
|
37
61
|
};
|
|
@@ -73,6 +97,54 @@ const permitAbi = [
|
|
|
73
97
|
|
|
74
98
|
function WalletStatus({ onDisconnect }: { onDisconnect: () => void }) {
|
|
75
99
|
const { ownerAddress } = useSbcApp();
|
|
100
|
+
const [eoaBalances, setEoaBalances] = useState<{ eth: string | null; sbc: string | null }>({ eth: null, sbc: null });
|
|
101
|
+
const [isLoadingEoaBalances, setIsLoadingEoaBalances] = useState(false);
|
|
102
|
+
|
|
103
|
+
// Fetch ETH and TestSBC balances for EOA wallet
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!ownerAddress) return;
|
|
106
|
+
|
|
107
|
+
const fetchEoaBalances = async () => {
|
|
108
|
+
setIsLoadingEoaBalances(true);
|
|
109
|
+
try {
|
|
110
|
+
const [ethBalance, sbcBalance] = await Promise.all([
|
|
111
|
+
publicClient.getBalance({ address: ownerAddress as `0x${string}` }),
|
|
112
|
+
publicClient.readContract({
|
|
113
|
+
address: SBC_TOKEN_ADDRESS(chain) as `0x${string}`,
|
|
114
|
+
abi: erc20Abi,
|
|
115
|
+
functionName: 'balanceOf',
|
|
116
|
+
args: [ownerAddress as `0x${string}`],
|
|
117
|
+
})
|
|
118
|
+
]);
|
|
119
|
+
setEoaBalances({ eth: ethBalance.toString(), sbc: (sbcBalance as bigint).toString() });
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('Failed to fetch EOA balances:', error);
|
|
122
|
+
setEoaBalances({ eth: '0', sbc: '0' });
|
|
123
|
+
} finally {
|
|
124
|
+
setIsLoadingEoaBalances(false);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
fetchEoaBalances();
|
|
129
|
+
}, [ownerAddress]);
|
|
130
|
+
|
|
131
|
+
const formatEthBalance = (balance: string | null): string => {
|
|
132
|
+
if (!balance) return '0.0000';
|
|
133
|
+
try {
|
|
134
|
+
return (Number(balance) / 1e18).toFixed(4);
|
|
135
|
+
} catch {
|
|
136
|
+
return '0.0000';
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const formatSbcBalance = (balance: string | null): string => {
|
|
141
|
+
if (!balance) return '0.00';
|
|
142
|
+
try {
|
|
143
|
+
return (Number(balance) / Math.pow(10, SBC_DECIMALS(chain))).toFixed(2);
|
|
144
|
+
} catch {
|
|
145
|
+
return '0.00';
|
|
146
|
+
}
|
|
147
|
+
};
|
|
76
148
|
|
|
77
149
|
if (!ownerAddress) return null;
|
|
78
150
|
|
|
@@ -94,6 +166,18 @@ function WalletStatus({ onDisconnect }: { onDisconnect: () => void }) {
|
|
|
94
166
|
<label>Chain:</label>
|
|
95
167
|
<div className="value">{chain.name}</div>
|
|
96
168
|
</div>
|
|
169
|
+
<div className="info-row">
|
|
170
|
+
<label>EOA ETH Balance:</label>
|
|
171
|
+
<div className="value">
|
|
172
|
+
{isLoadingEoaBalances ? 'Loading...' : `${formatEthBalance(eoaBalances.eth)} ETH`}
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
<div className="info-row">
|
|
176
|
+
<label>EOA {getTokenSymbol(chain)} Balance:</label>
|
|
177
|
+
<div className="value">
|
|
178
|
+
{isLoadingEoaBalances ? 'Loading...' : `${formatSbcBalance(eoaBalances.sbc)} ${getTokenSymbol(chain)}`}
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
97
181
|
</div>
|
|
98
182
|
);
|
|
99
183
|
}
|
|
@@ -207,9 +291,9 @@ function SmartAccountInfo() {
|
|
|
207
291
|
<div className="value">{formatEthBalance(account.balance)} ETH</div>
|
|
208
292
|
</div>
|
|
209
293
|
<div className="info-row">
|
|
210
|
-
<label>
|
|
294
|
+
<label>{getTokenSymbol(chain)} Balance:</label>
|
|
211
295
|
<div className="value">
|
|
212
|
-
{isLoadingBalance ? 'Loading...' : `${formatSbcBalance(sbcBalance)}
|
|
296
|
+
{isLoadingBalance ? 'Loading...' : `${formatSbcBalance(sbcBalance)} ${getTokenSymbol(chain)}`}
|
|
213
297
|
</div>
|
|
214
298
|
</div>
|
|
215
299
|
</div>
|
|
@@ -229,7 +313,7 @@ function SendSBCForm() {
|
|
|
229
313
|
try {
|
|
230
314
|
const ownerChecksum = getAddress(ownerAddress);
|
|
231
315
|
const spenderChecksum = getAddress(account.address);
|
|
232
|
-
const value = parseUnits('1', SBC_DECIMALS(chain)); // Send 1
|
|
316
|
+
const value = parseUnits('1', SBC_DECIMALS(chain)); // Send 1 token
|
|
233
317
|
const deadline = Math.floor(Date.now() / 1000) + 60 * 30; // 30 min
|
|
234
318
|
|
|
235
319
|
const signature = await getPermitSignature({
|
|
@@ -275,7 +359,7 @@ function SendSBCForm() {
|
|
|
275
359
|
|
|
276
360
|
return (
|
|
277
361
|
<div className="card">
|
|
278
|
-
<h3>💸 Send 1
|
|
362
|
+
<h3>💸 Send 1 {getTokenSymbol(chain)} Token</h3>
|
|
279
363
|
<div className="form-group">
|
|
280
364
|
<label>Recipient Address</label>
|
|
281
365
|
<input
|
|
@@ -289,11 +373,11 @@ function SendSBCForm() {
|
|
|
289
373
|
<span className="error-text">Invalid Ethereum address</span>
|
|
290
374
|
)}
|
|
291
375
|
</div>
|
|
292
|
-
|
|
376
|
+
|
|
293
377
|
<div className="status-section">
|
|
294
378
|
<div className="info-row">
|
|
295
379
|
<label>Amount:</label>
|
|
296
|
-
<div className="value">1.00
|
|
380
|
+
<div className="value">1.00 {getTokenSymbol(chain)}</div>
|
|
297
381
|
</div>
|
|
298
382
|
<div className="info-row">
|
|
299
383
|
<label>Gas fees:</label>
|
|
@@ -310,18 +394,18 @@ function SendSBCForm() {
|
|
|
310
394
|
disabled={!isFormValid || isLoading || !account}
|
|
311
395
|
className="primary"
|
|
312
396
|
>
|
|
313
|
-
{isLoading ? 'Waiting for signature...' :
|
|
397
|
+
{isLoading ? 'Waiting for signature...' : `Send 1 ${getTokenSymbol(chain)}`}
|
|
314
398
|
</button>
|
|
315
399
|
|
|
316
400
|
{isSuccess && data && (
|
|
317
401
|
<div className="success-message">
|
|
318
402
|
<p>✅ Transaction Successful!</p>
|
|
319
|
-
<a
|
|
403
|
+
<a
|
|
320
404
|
href={`${chainExplorer(chain)}/tx/${data.transactionHash}`}
|
|
321
405
|
target="_blank"
|
|
322
406
|
rel="noopener noreferrer"
|
|
323
407
|
>
|
|
324
|
-
View
|
|
408
|
+
View transaction: {data.transactionHash}
|
|
325
409
|
</a>
|
|
326
410
|
</div>
|
|
327
411
|
)}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
VITE_SBC_API_KEY={{apiKey}}
|
|
3
3
|
# Get your Dynamic Environment ID at https://app.dynamic.xyz/
|
|
4
4
|
VITE_DYNAMIC_ENVIRONMENT_ID=your_dynamic_env_id
|
|
5
|
-
#
|
|
6
|
-
VITE_CHAIN=
|
|
5
|
+
# Supported chains: "baseSepolia" | "base" | "radiusTestnet"
|
|
6
|
+
VITE_CHAIN={{chain}}
|
|
7
7
|
VITE_RPC_URL=
|
|
@@ -2,25 +2,48 @@ import { DynamicContextProvider, useDynamicContext, DynamicUserProfile, DynamicW
|
|
|
2
2
|
import { EthereumWalletConnectors } from '@dynamic-labs/ethereum';
|
|
3
3
|
import { ZeroDevSmartWalletConnectors } from '@dynamic-labs/ethereum-aa';
|
|
4
4
|
import { useSbcDynamic } from '@stablecoin.xyz/react';
|
|
5
|
+
import { radiusTestnet, TestSBC_CONTRACT_ADDRESS } from '@stablecoin.xyz/core';
|
|
5
6
|
import { baseSepolia, base, type Chain } from 'viem/chains';
|
|
6
7
|
import { createPublicClient, http, getAddress, parseUnits, encodeFunctionData, erc20Abi } from 'viem';
|
|
7
8
|
import { useEffect, useState } from 'react';
|
|
8
9
|
import './App.css';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const getChain = () => {
|
|
12
|
+
const chainEnv = import.meta.env.VITE_CHAIN;
|
|
13
|
+
if (chainEnv === 'base') return base;
|
|
14
|
+
if (chainEnv === 'radiusTestnet') return radiusTestnet;
|
|
15
|
+
return baseSepolia;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const chain = getChain();
|
|
11
19
|
const rpcUrl = import.meta.env.VITE_RPC_URL;
|
|
12
20
|
|
|
21
|
+
// Radius testnet uses TestSBC (a test token for development)
|
|
22
|
+
const TEST_SBC_DECIMALS = 6;
|
|
23
|
+
|
|
13
24
|
const SBC_TOKEN_ADDRESS = (chain: Chain) => {
|
|
14
25
|
if (chain.id === baseSepolia.id) return '0xf9FB20B8E097904f0aB7d12e9DbeE88f2dcd0F16';
|
|
15
26
|
if (chain.id === base.id) return '0xfdcC3dd6671eaB0709A4C0f3F53De9a333d80798';
|
|
27
|
+
if (chain.id === radiusTestnet.id) return TestSBC_CONTRACT_ADDRESS;
|
|
28
|
+
throw new Error('Unsupported chain');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const SBC_DECIMALS = (chain: Chain) => {
|
|
32
|
+
if (chain.id === baseSepolia.id) return 6;
|
|
33
|
+
if (chain.id === base.id) return 18;
|
|
34
|
+
if (chain.id === radiusTestnet.id) return TEST_SBC_DECIMALS;
|
|
16
35
|
throw new Error('Unsupported chain');
|
|
17
36
|
};
|
|
18
37
|
|
|
19
|
-
const
|
|
38
|
+
const getTokenSymbol = (chain: Chain) => {
|
|
39
|
+
if (chain.id === radiusTestnet.id) return 'TestSBC';
|
|
40
|
+
return 'SBC';
|
|
41
|
+
};
|
|
20
42
|
|
|
21
43
|
const chainExplorer = (chain: Chain) => {
|
|
22
44
|
if (chain.id === baseSepolia.id) return 'https://sepolia.basescan.org';
|
|
23
45
|
if (chain.id === base.id) return 'https://basescan.org';
|
|
46
|
+
if (chain.id === radiusTestnet.id) return 'https://testnet.radiustech.xyz/testnet/explorer';
|
|
24
47
|
return '';
|
|
25
48
|
};
|
|
26
49
|
|
|
@@ -74,7 +97,8 @@ function WalletStatus() {
|
|
|
74
97
|
})
|
|
75
98
|
]);
|
|
76
99
|
setBalances({ eth: ethBalance.toString(), sbc: (sbcBalance as bigint).toString() });
|
|
77
|
-
} catch {
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Failed to fetch EOA balances:', error);
|
|
78
102
|
setBalances({ eth: null, sbc: null });
|
|
79
103
|
}
|
|
80
104
|
})();
|
|
@@ -93,10 +117,10 @@ function WalletStatus() {
|
|
|
93
117
|
<p className="text-xs text-green-600 mb-2">Connected via Dynamic SDK</p>
|
|
94
118
|
<p className="text-xs text-green-600 mb-2"><strong>Chain:</strong> {chain.name} (ID: {chain.id})</p>
|
|
95
119
|
<div className="mt-2 pt-2 border-t border-green-200">
|
|
96
|
-
<p className="text-xs font-medium text-green-700 mb-1">Wallet Balances:</p>
|
|
120
|
+
<p className="text-xs font-medium text-green-700 mb-1">EOA Wallet Balances:</p>
|
|
97
121
|
<div className="flex gap-4">
|
|
98
122
|
<span className="text-xs text-green-600"><strong>ETH:</strong> {fmtEth(balances.eth)}</span>
|
|
99
|
-
<span className="text-xs text-green-600"><strong>
|
|
123
|
+
<span className="text-xs text-green-600"><strong>{getTokenSymbol(chain)}:</strong> {fmtSbc(balances.sbc)}</span>
|
|
100
124
|
</div>
|
|
101
125
|
</div>
|
|
102
126
|
</div>
|
|
@@ -118,7 +142,10 @@ function SmartAccountInfo({ account, refreshAccount, isLoadingAccount, accountEr
|
|
|
118
142
|
args: [account.address as `0x${string}`],
|
|
119
143
|
});
|
|
120
144
|
setSbcBalance((bal as bigint).toString());
|
|
121
|
-
} catch
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('Failed to fetch smart account SBC balance:', error);
|
|
147
|
+
setSbcBalance('0');
|
|
148
|
+
}
|
|
122
149
|
})();
|
|
123
150
|
}, [account?.address]);
|
|
124
151
|
|
|
@@ -136,13 +163,8 @@ function SmartAccountInfo({ account, refreshAccount, isLoadingAccount, accountEr
|
|
|
136
163
|
<div className="flex justify-between"><span className="text-purple-700">Smart Account Address:</span><span className="font-mono text-xs text-purple-600 break-all">{account.address}</span></div>
|
|
137
164
|
<div className="flex justify-between"><span className="text-purple-700">Deployed:</span><span className="text-purple-600">{account.isDeployed ? '✅ Yes' : '⏳ On first transaction'}</span></div>
|
|
138
165
|
<div className="flex justify-between"><span className="text-purple-700">Nonce:</span><span className="text-purple-600">{account.nonce}</span></div>
|
|
139
|
-
<div className="
|
|
140
|
-
|
|
141
|
-
<div className="space-y-1">
|
|
142
|
-
<div className="flex justify-between"><span className="text-purple-700">ETH:</span><span className="text-purple-600 font-mono text-xs">{fmtEth(account.balance)} ETH</span></div>
|
|
143
|
-
<div className="flex justify-between"><span className="text-purple-700">SBC:</span><span className="text-purple-600 font-mono text-xs">{fmtSbc(sbcBalance)} SBC</span></div>
|
|
144
|
-
</div>
|
|
145
|
-
</div>
|
|
166
|
+
<div className="flex justify-between"><span className="text-purple-700">ETH Balance:</span><span className="text-purple-600 font-mono text-xs">{fmtEth(account.balance)} ETH</span></div>
|
|
167
|
+
<div className="flex justify-between"><span className="text-purple-700">{getTokenSymbol(chain)} Balance:</span><span className="text-purple-600 font-mono text-xs">{fmtSbc(sbcBalance)} {getTokenSymbol(chain)}</span></div>
|
|
146
168
|
</div>
|
|
147
169
|
{accountError && <p className="mt-2 text-xs text-red-600">{String(accountError)}</p>}
|
|
148
170
|
</div>
|
|
@@ -216,29 +238,29 @@ function TransactionForm({ account, sbcAppKit }: { account: any; sbcAppKit: any
|
|
|
216
238
|
|
|
217
239
|
return (
|
|
218
240
|
<div className="p-4 bg-white border border-gray-200 rounded-lg shadow-sm">
|
|
219
|
-
<h3 className="font-semibold text-gray-800 mb-4">💸 Send
|
|
241
|
+
<h3 className="font-semibold text-gray-800 mb-4">💸 Send {getTokenSymbol(chain)} Tokens</h3>
|
|
220
242
|
<div className="space-y-4">
|
|
221
243
|
<div>
|
|
222
244
|
<label className="block text-sm font-medium text-gray-700 mb-2">Recipient Address</label>
|
|
223
245
|
<input type="text" value={recipient} onChange={(e) => setRecipient(e.target.value)} placeholder="0x..." className="w-full px-3 py-2 text-xs font-mono border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 border-gray-300" />
|
|
224
246
|
</div>
|
|
225
247
|
<div>
|
|
226
|
-
<label className="block text-sm font-medium text-gray-700 mb-2">Amount (
|
|
248
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">Amount ({getTokenSymbol(chain)})</label>
|
|
227
249
|
<input type="number" value={amount} onChange={(e) => setAmount(e.target.value)} placeholder="1.0" step="0.000001" min="0" className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 border-gray-300" />
|
|
228
250
|
</div>
|
|
229
251
|
<div className="p-3 bg-gray-50 rounded">
|
|
230
|
-
<div className="flex justify-between text-sm"><span>Amount:</span><span className="font-medium">{amount}
|
|
252
|
+
<div className="flex justify-between text-sm"><span>Amount:</span><span className="font-medium">{amount} {getTokenSymbol(chain)}</span></div>
|
|
231
253
|
<div className="flex justify-between text-xs text-gray-600"><span>Gas fees:</span><span>Covered by SBC Paymaster ✨</span></div>
|
|
232
254
|
<div className="flex justify-between text-xs text-gray-600"><span>Signing:</span><span>Your Dynamic wallet will prompt to sign 🖊️</span></div>
|
|
233
255
|
</div>
|
|
234
256
|
<button onClick={sendTx} disabled={!isValid || status==='loading' || !account} className="w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
|
235
|
-
{status==='loading' ? 'Waiting for signature...' : `Send ${amount}
|
|
257
|
+
{status==='loading' ? 'Waiting for signature...' : `Send ${amount} ${getTokenSymbol(chain)}`}
|
|
236
258
|
</button>
|
|
237
259
|
{status==='success' && result && (
|
|
238
260
|
<div className="p-3 bg-green-50 border border-green-200 rounded">
|
|
239
261
|
<p className="text-sm text-green-800 font-medium">✅ Transaction Submitted</p>
|
|
240
262
|
<p className="text-xs text-green-600 font-mono break-all mt-1">
|
|
241
|
-
<a href={`${chainExplorer(chain)}/tx/${result.transactionHash}`} target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">View
|
|
263
|
+
<a href={`${chainExplorer(chain)}/tx/${result.transactionHash}`} target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">View transaction: {result.transactionHash}</a>
|
|
242
264
|
</p>
|
|
243
265
|
</div>
|
|
244
266
|
)}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
VITE_SBC_API_KEY={{apiKey}}
|
|
3
3
|
# Get your Para API Key at https://developer.getpara.com/
|
|
4
4
|
VITE_PARA_API_KEY=your_para_api_key
|
|
5
|
-
#
|
|
6
|
-
VITE_CHAIN=
|
|
5
|
+
# Supported chains: "baseSepolia" | "base" | "radiusTestnet"
|
|
6
|
+
VITE_CHAIN={{chain}}
|
|
7
7
|
VITE_RPC_URL=
|
|
@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
2
2
|
import { Environment, ParaProvider } from '@getpara/react-sdk';
|
|
3
3
|
import '@getpara/react-sdk/styles.css';
|
|
4
4
|
import { useSbcPara } from '@stablecoin.xyz/react';
|
|
5
|
+
import { radiusTestnet, TestSBC_CONTRACT_ADDRESS } from '@stablecoin.xyz/core';
|
|
5
6
|
import { useAccount, useWallet, useSignMessage } from '@getpara/react-sdk';
|
|
6
7
|
import { baseSepolia, base, type Chain } from 'viem/chains';
|
|
7
8
|
import { createPublicClient, http, getAddress, parseUnits, encodeFunctionData, erc20Abi } from 'viem';
|
|
@@ -12,15 +13,39 @@ import { buildPermitTypedData, hashPermitTypedData, hex32ToBase64, normalizeSign
|
|
|
12
13
|
import { usePara } from './hooks/usePara';
|
|
13
14
|
|
|
14
15
|
const queryClient = new QueryClient();
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
const getChain = () => {
|
|
18
|
+
const chainEnv = import.meta.env.VITE_CHAIN;
|
|
19
|
+
if (chainEnv === 'base') return base;
|
|
20
|
+
if (chainEnv === 'radiusTestnet') return radiusTestnet;
|
|
21
|
+
return baseSepolia;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const chain = getChain();
|
|
16
25
|
const rpcUrl = import.meta.env.VITE_RPC_URL;
|
|
17
26
|
|
|
27
|
+
// Radius testnet uses TestSBC (a test token for development)
|
|
28
|
+
const TEST_SBC_DECIMALS = 6;
|
|
29
|
+
|
|
18
30
|
const SBC_TOKEN_ADDRESS = (chain: Chain) => {
|
|
19
31
|
if (chain.id === baseSepolia.id) return '0xf9FB20B8E097904f0aB7d12e9DbeE88f2dcd0F16';
|
|
20
32
|
if (chain.id === base.id) return '0xfdcC3dd6671eaB0709A4C0f3F53De9a333d80798';
|
|
33
|
+
if (chain.id === radiusTestnet.id) return TestSBC_CONTRACT_ADDRESS;
|
|
34
|
+
throw new Error('Unsupported chain');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const SBC_DECIMALS = (chain: Chain) => {
|
|
38
|
+
if (chain.id === baseSepolia.id) return 6;
|
|
39
|
+
if (chain.id === base.id) return 18;
|
|
40
|
+
if (chain.id === radiusTestnet.id) return TEST_SBC_DECIMALS;
|
|
21
41
|
throw new Error('Unsupported chain');
|
|
22
42
|
};
|
|
23
|
-
|
|
43
|
+
|
|
44
|
+
const getTokenSymbol = (chain: Chain) => {
|
|
45
|
+
if (chain.id === radiusTestnet.id) return 'TestSBC';
|
|
46
|
+
return 'SBC';
|
|
47
|
+
};
|
|
48
|
+
|
|
24
49
|
const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
|
|
25
50
|
|
|
26
51
|
// ERC20 + EIP-2612 nonces helper ABI
|
|
@@ -58,7 +83,12 @@ const permitAbi = [
|
|
|
58
83
|
}
|
|
59
84
|
] as const;
|
|
60
85
|
|
|
61
|
-
const chainExplorer = (c: Chain) =>
|
|
86
|
+
const chainExplorer = (c: Chain) => {
|
|
87
|
+
if (c.id === baseSepolia.id) return 'https://sepolia.basescan.org';
|
|
88
|
+
if (c.id === base.id) return 'https://basescan.org';
|
|
89
|
+
if (c.id === radiusTestnet.id) return 'https://testnet.radiustech.xyz/testnet/explorer';
|
|
90
|
+
return '';
|
|
91
|
+
};
|
|
62
92
|
|
|
63
93
|
function SmartAccountInfo({ account, refreshAccount, isLoadingAccount, accountError }: any) {
|
|
64
94
|
const [sbcBalance, setSbcBalance] = useState<string | null>(null);
|
|
@@ -73,7 +103,10 @@ function SmartAccountInfo({ account, refreshAccount, isLoadingAccount, accountEr
|
|
|
73
103
|
args: [account.address as `0x${string}`],
|
|
74
104
|
});
|
|
75
105
|
setSbcBalance((bal as bigint).toString());
|
|
76
|
-
} catch
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Failed to fetch smart account SBC balance:', error);
|
|
108
|
+
setSbcBalance('0');
|
|
109
|
+
}
|
|
77
110
|
})();
|
|
78
111
|
}, [account?.address]);
|
|
79
112
|
|
|
@@ -91,13 +124,8 @@ function SmartAccountInfo({ account, refreshAccount, isLoadingAccount, accountEr
|
|
|
91
124
|
<div className="flex justify-between"><span className="text-purple-700">Smart Account Address:</span><span className="font-mono text-xs text-purple-600 break-all">{account.address}</span></div>
|
|
92
125
|
<div className="flex justify-between"><span className="text-purple-700">Deployed:</span><span className="text-purple-600">{account.isDeployed ? '✅ Yes' : '⏳ On first transaction'}</span></div>
|
|
93
126
|
<div className="flex justify-between"><span className="text-purple-700">Nonce:</span><span className="text-purple-600">{account.nonce}</span></div>
|
|
94
|
-
<div className="
|
|
95
|
-
|
|
96
|
-
<div className="space-y-1">
|
|
97
|
-
<div className="flex justify-between"><span className="text-purple-700">ETH:</span><span className="text-purple-600 font-mono text-xs">{fmtEth(account.balance)} ETH</span></div>
|
|
98
|
-
<div className="flex justify-between"><span className="text-purple-700">SBC:</span><span className="text-purple-600 font-mono text-xs">{fmtSbc(sbcBalance)} SBC</span></div>
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
127
|
+
<div className="flex justify-between"><span className="text-purple-700">ETH Balance:</span><span className="text-purple-600 font-mono text-xs">{fmtEth(account.balance)} ETH</span></div>
|
|
128
|
+
<div className="flex justify-between"><span className="text-purple-700">{getTokenSymbol(chain)} Balance:</span><span className="text-purple-600 font-mono text-xs">{fmtSbc(sbcBalance)} {getTokenSymbol(chain)}</span></div>
|
|
101
129
|
</div>
|
|
102
130
|
{accountError && <p className="mt-2 text-xs text-red-600">{String(accountError)}</p>}
|
|
103
131
|
</div>
|
|
@@ -186,29 +214,29 @@ function TransactionForm({ account, sbcAppKit }: { account: any; sbcAppKit: any
|
|
|
186
214
|
|
|
187
215
|
return (
|
|
188
216
|
<div className="p-4 bg-white border border-gray-200 rounded-lg shadow-sm">
|
|
189
|
-
<h3 className="font-semibold text-gray-800 mb-4">💸 Send
|
|
217
|
+
<h3 className="font-semibold text-gray-800 mb-4">💸 Send {getTokenSymbol(chain)} Tokens</h3>
|
|
190
218
|
<div className="space-y-4">
|
|
191
219
|
<div>
|
|
192
220
|
<label className="block text-sm font-medium text-gray-700 mb-2">Recipient Address</label>
|
|
193
221
|
<input type="text" value={recipient} onChange={(e) => setRecipient(e.target.value)} placeholder="0x..." className="w-full px-3 py-2 text-xs font-mono border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 border-gray-300" />
|
|
194
222
|
</div>
|
|
195
223
|
<div>
|
|
196
|
-
<label className="block text-sm font-medium text-gray-700 mb-2">Amount (
|
|
224
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">Amount ({getTokenSymbol(chain)})</label>
|
|
197
225
|
<input type="number" value={amount} onChange={(e) => setAmount(e.target.value)} placeholder="1.0" step="0.000001" min="0" className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 border-gray-300" />
|
|
198
226
|
</div>
|
|
199
227
|
<div className="p-3 bg-gray-50 rounded">
|
|
200
|
-
<div className="flex justify-between text-sm"><span>Amount:</span><span className="font-medium">{amount}
|
|
228
|
+
<div className="flex justify-between text-sm"><span>Amount:</span><span className="font-medium">{amount} {getTokenSymbol(chain)}</span></div>
|
|
201
229
|
<div className="flex justify-between text-xs text-gray-600"><span>Gas fees:</span><span>Covered by SBC Paymaster ✨</span></div>
|
|
202
230
|
<div className="flex justify-between text-xs text-gray-600"><span>Signing:</span><span>Your wallet will prompt to sign 🖊️</span></div>
|
|
203
231
|
</div>
|
|
204
232
|
<button onClick={sendTx} disabled={!isValid || status==='loading' || !account} className="w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
|
205
|
-
{status==='loading' ? 'Waiting for signature...' : `Send ${amount}
|
|
233
|
+
{status==='loading' ? 'Waiting for signature...' : `Send ${amount} ${getTokenSymbol(chain)}`}
|
|
206
234
|
</button>
|
|
207
235
|
{status==='success' && result && (
|
|
208
236
|
<div className="p-3 bg-green-50 border border-green-200 rounded">
|
|
209
237
|
<p className="text-sm text-green-800 font-medium">✅ Transaction Submitted</p>
|
|
210
238
|
<p className="text-xs text-green-600 font-mono break-all mt-1">
|
|
211
|
-
<a href={`${chainExplorer(chain)}/tx/${result.transactionHash}`} target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">View
|
|
239
|
+
<a href={`${chainExplorer(chain)}/tx/${result.transactionHash}`} target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">View transaction: {result.transactionHash}</a>
|
|
212
240
|
</p>
|
|
213
241
|
</div>
|
|
214
242
|
)}
|