create-sbc-app 0.1.1
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 +105 -0
- package/bin/cli.js +104 -0
- package/bin/copyTemplate.js +34 -0
- package/package.json +55 -0
- package/src/cli.ts +115 -0
- package/src/copyTemplate.ts +42 -0
- package/src/index.js +221 -0
- package/src/types/prompts.d.ts +3 -0
- package/templates/README.md +48 -0
- package/templates/react/.env +2 -0
- package/templates/react/.eslintrc.cjs +18 -0
- package/templates/react/README.md +146 -0
- package/templates/react/eslint.config.js +32 -0
- package/templates/react/index.html +18 -0
- package/templates/react/package.json +25 -0
- package/templates/react/public/sbc-logo.png +0 -0
- package/templates/react/src/App.css +604 -0
- package/templates/react/src/App.tsx +505 -0
- package/templates/react/src/env.d.ts +1 -0
- package/templates/react/src/index.css +13 -0
- package/templates/react/src/main.tsx +10 -0
- package/templates/react/tsconfig.json +25 -0
- package/templates/react/tsconfig.node.json +10 -0
- package/templates/react/vite.config.ts +19 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# create-sbc-app
|
|
2
|
+
|
|
3
|
+
This directory contains ready-to-use templates for quickly starting new projects with the SBC App Kit. Each template is a minimal, fully functional app that demonstrates best practices for integrating @stablecoin.xyz/core and @stablecoin.xyz/react.
|
|
4
|
+
|
|
5
|
+
## Available Templates
|
|
6
|
+
|
|
7
|
+
- **react/** β Minimal React app with SBC integration (Vite)
|
|
8
|
+
|
|
9
|
+
## How to Use a Template
|
|
10
|
+
|
|
11
|
+
1. **Copy the template directory** you want to use:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cp -r create-sbc-app/react my-new-sbc-app
|
|
15
|
+
# or for Next.js:
|
|
16
|
+
cp -r create-sbc-app/nextjs my-new-sbc-next-app
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. **Install dependencies:**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd my-new-sbc-app
|
|
23
|
+
pnpm install
|
|
24
|
+
# or
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
3. **Run the app:**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm dev
|
|
32
|
+
# or
|
|
33
|
+
npm run dev
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
4. **Customize as needed:**
|
|
37
|
+
- Update the API key and config in `src/App.tsx` or `app/page.tsx`.
|
|
38
|
+
- Follow the templateβs README for more details.
|
|
39
|
+
|
|
40
|
+
## Keeping Templates Up to Date
|
|
41
|
+
|
|
42
|
+
- All templates use the latest published versions of SBC packages.
|
|
43
|
+
- Code and config are kept in sync with the main repoβs best practices.
|
|
44
|
+
- If you find an issue, please open a PR or issue in the main repo.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
Each template has its own README with specific instructions and details.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: { browser: true, es2020: true },
|
|
4
|
+
extends: [
|
|
5
|
+
'eslint:recommended',
|
|
6
|
+
'@typescript-eslint/recommended',
|
|
7
|
+
'plugin:react-hooks/recommended',
|
|
8
|
+
],
|
|
9
|
+
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
|
10
|
+
parser: '@typescript-eslint/parser',
|
|
11
|
+
plugins: ['react-refresh'],
|
|
12
|
+
rules: {
|
|
13
|
+
'react-refresh/only-export-components': [
|
|
14
|
+
'warn',
|
|
15
|
+
{ allowConstantExport: true },
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
A gasless smart account application powered by [SBC (Stable Coin Inc)](https://stablecoin.xyz).
|
|
4
|
+
|
|
5
|
+
## π Quick Start
|
|
6
|
+
|
|
7
|
+
### 1. Install Dependencies
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### 2. Configure Environment Variables
|
|
13
|
+
Copy the example environment file and add your SBC API key:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cp .env.example .env # Optional: for local overrides
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Edit `.env` and add your SBC API key:
|
|
20
|
+
```bash
|
|
21
|
+
VITE_SBC_API_KEY=your_api_key_here
|
|
22
|
+
VITE_SBC_CHAIN={{chain}}
|
|
23
|
+
VITE_SBC_DEBUG=true
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
> **Get your API key:** Visit the [SBC Dashboard](https://dashboard.stablecoin.xyz) to create an account and get your API key.
|
|
27
|
+
|
|
28
|
+
### 3. Start the Development Server
|
|
29
|
+
```bash
|
|
30
|
+
npm run dev
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Your app will be available at `http://localhost:3000` π
|
|
34
|
+
|
|
35
|
+
## π₯ What You'll See
|
|
36
|
+
|
|
37
|
+
This example app demonstrates:
|
|
38
|
+
|
|
39
|
+
- **π Wallet Connection**: Connect any Ethereum wallet
|
|
40
|
+
- **π¦ Smart Account Creation**: Automatically creates a gasless smart account
|
|
41
|
+
- **β½ Gasless Transactions**: Send transactions without paying gas fees
|
|
42
|
+
- **π° Balance Checking**: Check your account balance
|
|
43
|
+
- **π§ Ready-to-Use Setup**: Environment variables and error handling included
|
|
44
|
+
|
|
45
|
+
## π How It Works
|
|
46
|
+
|
|
47
|
+
### Environment Variables (Vite)
|
|
48
|
+
The app uses Vite's environment variables with the `VITE_` prefix:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const config = {
|
|
52
|
+
apiKey: import.meta.env.VITE_SBC_API_KEY,
|
|
53
|
+
chain: {{chain}},
|
|
54
|
+
debug: import.meta.env.VITE_SBC_DEBUG === 'true'
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### SBC Integration
|
|
59
|
+
```typescript
|
|
60
|
+
import { SbcProvider, useSbcApp, WalletConnect } from '@stablecoin.xyz/react';
|
|
61
|
+
|
|
62
|
+
// 1. Wrap your app with SbcProvider
|
|
63
|
+
<SbcProvider config={config}>
|
|
64
|
+
<YourApp />
|
|
65
|
+
</SbcProvider>
|
|
66
|
+
|
|
67
|
+
// 2. Use the SBC hooks
|
|
68
|
+
const { sbcAppKit, account, isInitialized } = useSbcApp();
|
|
69
|
+
|
|
70
|
+
// 3. Send gasless transactions
|
|
71
|
+
const tx = await sbcAppKit.sendTransaction({
|
|
72
|
+
to: recipientAddress,
|
|
73
|
+
value: parseEther('0.001'),
|
|
74
|
+
data: '0x'
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## π Available Scripts
|
|
79
|
+
|
|
80
|
+
- `npm run dev` - Start development server
|
|
81
|
+
- `npm run build` - Build for production
|
|
82
|
+
- `npm run preview` - Preview production build
|
|
83
|
+
- `npm run lint` - Run ESLint
|
|
84
|
+
|
|
85
|
+
## π§ Development
|
|
86
|
+
|
|
87
|
+
### Project Structure
|
|
88
|
+
```
|
|
89
|
+
src/
|
|
90
|
+
βββ App.tsx # Main app with SBC integration
|
|
91
|
+
βββ main.tsx # Vite entry point
|
|
92
|
+
βββ App.css # Styles
|
|
93
|
+
βββ index.css # Global styles
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Adding Your Own Features
|
|
97
|
+
|
|
98
|
+
1. **Custom Transactions**: Modify the `sendGaslessTransaction` function in `App.tsx`
|
|
99
|
+
2. **Smart Contract Interactions**: Use `sbcAppKit.sendTransaction()` with contract calls
|
|
100
|
+
3. **Additional UI**: Add new components and import them in `App.tsx`
|
|
101
|
+
|
|
102
|
+
## π Chain Configuration
|
|
103
|
+
|
|
104
|
+
This app is configured for **{{chain}}**. To use a different chain:
|
|
105
|
+
|
|
106
|
+
1. Update `.env`:
|
|
107
|
+
```bash
|
|
108
|
+
VITE_SBC_CHAIN=your_chain_here
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
2. Update the import in `App.tsx`:
|
|
112
|
+
```typescript
|
|
113
|
+
import { yourChain } from 'viem/chains';
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## π Learn More
|
|
117
|
+
|
|
118
|
+
- [SBC Documentation](https://docs.stablecoin.xyz)
|
|
119
|
+
- [SBC React SDK](https://www.npmjs.com/package/@stablecoin.xyz/react)
|
|
120
|
+
- [Viem Documentation](https://viem.sh)
|
|
121
|
+
- [React Documentation](https://react.dev)
|
|
122
|
+
|
|
123
|
+
## π Troubleshooting
|
|
124
|
+
|
|
125
|
+
### "Configuration Required" Error
|
|
126
|
+
- Make sure you've set `VITE_SBC_API_KEY` in your `.env` file
|
|
127
|
+
- Restart the dev server after changing environment variables
|
|
128
|
+
|
|
129
|
+
### Transaction Failures
|
|
130
|
+
- Check that you're on the correct network ({{chain}})
|
|
131
|
+
- Ensure your wallet has a small amount of ETH for account deployment
|
|
132
|
+
- Check the browser console for detailed error messages
|
|
133
|
+
|
|
134
|
+
### Build Issues
|
|
135
|
+
- Make sure all dependencies are installed: `npm install`
|
|
136
|
+
- Try clearing the cache: `rm -rf node_modules package-lock.json && npm install`
|
|
137
|
+
|
|
138
|
+
## π Security
|
|
139
|
+
|
|
140
|
+
- Never commit your `.env` file with real API keys
|
|
141
|
+
- Use `.env.local` for local development overrides
|
|
142
|
+
- The `.env` file in this template is for demonstration only
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
**Happy building with SBC! π**
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from '@typescript-eslint/eslint-plugin'
|
|
6
|
+
import tsparser from '@typescript-eslint/parser'
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
{ ignores: ['dist'] },
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
globals: globals.browser,
|
|
15
|
+
parser: tsparser,
|
|
16
|
+
},
|
|
17
|
+
plugins: {
|
|
18
|
+
'@typescript-eslint': tseslint,
|
|
19
|
+
'react-hooks': reactHooks,
|
|
20
|
+
'react-refresh': reactRefresh,
|
|
21
|
+
},
|
|
22
|
+
rules: {
|
|
23
|
+
...js.configs.recommended.rules,
|
|
24
|
+
...tseslint.configs.recommended.rules,
|
|
25
|
+
...reactHooks.configs.recommended.rules,
|
|
26
|
+
'react-refresh/only-export-components': [
|
|
27
|
+
'warn',
|
|
28
|
+
{ allowConstantExport: true },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/sbc-logo.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<meta name="theme-color" content="#000000" />
|
|
8
|
+
<meta
|
|
9
|
+
name="description"
|
|
10
|
+
content="{{projectName}} - SBC-powered application"
|
|
11
|
+
/>
|
|
12
|
+
<title>{{projectName}}</title>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<div id="root"></div>
|
|
16
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc && vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@stablecoin.xyz/core": "latest",
|
|
13
|
+
"@stablecoin.xyz/react": "latest",
|
|
14
|
+
"react": "^18.2.0",
|
|
15
|
+
"react-dom": "^18.2.0",
|
|
16
|
+
"viem": "^2.31.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/react": "^18.2.0",
|
|
20
|
+
"@types/react-dom": "^18.2.0",
|
|
21
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
22
|
+
"typescript": "^5.0.0",
|
|
23
|
+
"vite": "^5.0.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
Binary file
|