@payai/x402-solana-react 1.0.0 → 1.0.2
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 +155 -36
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -5,12 +5,14 @@ A reusable React component library that provides drop-in paywall functionality f
|
|
|
5
5
|
## 🚀 Features
|
|
6
6
|
|
|
7
7
|
- ✅ **Drop-in React Components**: Easy integration with existing apps
|
|
8
|
+
- ✅ **Auto-Setup Providers**: Automatically configures wallet providers (or use your own)
|
|
8
9
|
- ✅ **Solana Native**: Built specifically for Solana blockchain
|
|
9
10
|
- ✅ **Multi-Wallet Support**: Works with Phantom, Solflare, and more
|
|
11
|
+
- ✅ **Multiple Themes**: Light, Dark, Solana, Seeker, Terminal themes
|
|
10
12
|
- ✅ **Tailwind CSS**: Utility-first styling with customization
|
|
11
13
|
- ✅ **shadcn/ui**: Accessible, beautiful components
|
|
12
14
|
- ✅ **TypeScript**: Full type safety and IntelliSense
|
|
13
|
-
- ✅ **
|
|
15
|
+
- ✅ **Network Auto-Detection**: Automatically configures mainnet/devnet
|
|
14
16
|
|
|
15
17
|
## 📋 Prerequisites
|
|
16
18
|
|
|
@@ -22,11 +24,11 @@ A reusable React component library that provides drop-in paywall functionality f
|
|
|
22
24
|
## 📦 Installation
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
|
-
npm install x402-solana-react
|
|
27
|
+
npm install @payai/x402-solana-react
|
|
26
28
|
# or
|
|
27
|
-
yarn add x402-solana-react
|
|
29
|
+
yarn add @payai/x402-solana-react
|
|
28
30
|
# or
|
|
29
|
-
pnpm add x402-solana-react
|
|
31
|
+
pnpm add @payai/x402-solana-react
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
### Install Peer Dependencies
|
|
@@ -41,13 +43,36 @@ npm install @solana/wallet-adapter-react @solana/wallet-adapter-react-ui @solana
|
|
|
41
43
|
|
|
42
44
|
### 1. Import Styles
|
|
43
45
|
|
|
44
|
-
Import the
|
|
46
|
+
Import the required styles in your main file (e.g., `main.tsx` or `App.tsx`):
|
|
45
47
|
|
|
46
48
|
```tsx
|
|
47
|
-
import 'x402-solana-react/styles';
|
|
49
|
+
import '@payai/x402-solana-react/styles';
|
|
50
|
+
import '@solana/wallet-adapter-react-ui/styles.css';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Wallet Provider Setup (Optional)
|
|
54
|
+
|
|
55
|
+
**Option A: Auto-Setup (Recommended)** 🎉
|
|
56
|
+
|
|
57
|
+
The component automatically sets up wallet providers for you! Just use it directly:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { X402Paywall } from '@payai/x402-solana-react';
|
|
61
|
+
|
|
62
|
+
function App() {
|
|
63
|
+
return (
|
|
64
|
+
<X402Paywall
|
|
65
|
+
amount={0.01}
|
|
66
|
+
description="Premium Content"
|
|
67
|
+
network="solana" // Automatically configures mainnet
|
|
68
|
+
>
|
|
69
|
+
<YourPremiumContent />
|
|
70
|
+
</X402Paywall>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
48
73
|
```
|
|
49
74
|
|
|
50
|
-
|
|
75
|
+
**Option B: Manual Setup** (if you need custom wallet configuration)
|
|
51
76
|
|
|
52
77
|
Wrap your app with Solana wallet providers:
|
|
53
78
|
|
|
@@ -57,10 +82,9 @@ import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react
|
|
|
57
82
|
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
|
|
58
83
|
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
|
|
59
84
|
import { clusterApiUrl } from '@solana/web3.js';
|
|
60
|
-
import '@solana/wallet-adapter-react-ui/styles.css';
|
|
61
85
|
|
|
62
86
|
function App() {
|
|
63
|
-
const network = WalletAdapterNetwork.
|
|
87
|
+
const network = WalletAdapterNetwork.Mainnet;
|
|
64
88
|
const endpoint = clusterApiUrl(network);
|
|
65
89
|
const wallets = [
|
|
66
90
|
new PhantomWalletAdapter(),
|
|
@@ -69,9 +93,16 @@ function App() {
|
|
|
69
93
|
|
|
70
94
|
return (
|
|
71
95
|
<ConnectionProvider endpoint={endpoint}>
|
|
72
|
-
<WalletProvider wallets={wallets} autoConnect>
|
|
96
|
+
<WalletProvider wallets={wallets} autoConnect={false}>
|
|
73
97
|
<WalletModalProvider>
|
|
74
|
-
|
|
98
|
+
<X402Paywall
|
|
99
|
+
amount={0.01}
|
|
100
|
+
description="Premium Content"
|
|
101
|
+
network="solana"
|
|
102
|
+
autoSetupProviders={false} // Disable auto-setup
|
|
103
|
+
>
|
|
104
|
+
<YourPremiumContent />
|
|
105
|
+
</X402Paywall>
|
|
75
106
|
</WalletModalProvider>
|
|
76
107
|
</WalletProvider>
|
|
77
108
|
</ConnectionProvider>
|
|
@@ -81,19 +112,19 @@ function App() {
|
|
|
81
112
|
|
|
82
113
|
## 🎯 Quick Start
|
|
83
114
|
|
|
115
|
+
### Simplest Example (Auto-Setup)
|
|
116
|
+
|
|
84
117
|
```tsx
|
|
85
|
-
import { X402Paywall } from 'x402-solana-react';
|
|
86
|
-
import
|
|
118
|
+
import { X402Paywall } from '@payai/x402-solana-react';
|
|
119
|
+
import '@payai/x402-solana-react/styles';
|
|
120
|
+
import '@solana/wallet-adapter-react-ui/styles.css';
|
|
87
121
|
|
|
88
122
|
function PremiumPage() {
|
|
89
|
-
const wallet = useWallet();
|
|
90
|
-
|
|
91
123
|
return (
|
|
92
124
|
<X402Paywall
|
|
93
|
-
amount={
|
|
125
|
+
amount={0.02}
|
|
94
126
|
description="Premium AI Chat Access"
|
|
95
|
-
|
|
96
|
-
network="solana-devnet"
|
|
127
|
+
network="solana" // Use 'solana' for mainnet, 'solana-devnet' for testing
|
|
97
128
|
onPaymentSuccess={(txId) => console.log('Payment successful!', txId)}
|
|
98
129
|
>
|
|
99
130
|
<PremiumContent />
|
|
@@ -102,16 +133,82 @@ function PremiumPage() {
|
|
|
102
133
|
}
|
|
103
134
|
```
|
|
104
135
|
|
|
105
|
-
|
|
136
|
+
### With Custom RPC (Recommended for Production)
|
|
106
137
|
|
|
107
|
-
|
|
138
|
+
```tsx
|
|
139
|
+
import { X402Paywall } from '@payai/x402-solana-react';
|
|
140
|
+
|
|
141
|
+
function PremiumPage() {
|
|
142
|
+
// Set via environment variable: VITE_SOLANA_RPC_URL
|
|
143
|
+
const rpcUrl = import.meta.env.VITE_SOLANA_RPC_URL;
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<X402Paywall
|
|
147
|
+
amount={0.02}
|
|
148
|
+
description="Premium Content"
|
|
149
|
+
network="solana"
|
|
150
|
+
rpcUrl={rpcUrl} // Avoids rate limiting on public RPCs
|
|
151
|
+
onPaymentSuccess={(txId) => {
|
|
152
|
+
console.log('Payment successful!', txId);
|
|
153
|
+
// Update your backend, show success message, etc.
|
|
154
|
+
}}
|
|
155
|
+
onPaymentError={(error) => {
|
|
156
|
+
console.error('Payment failed:', error);
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
<PremiumContent />
|
|
160
|
+
</X402Paywall>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## 🎨 Themes & Styling
|
|
166
|
+
|
|
167
|
+
The component comes with multiple built-in themes:
|
|
168
|
+
|
|
169
|
+
### Available Themes
|
|
170
|
+
|
|
171
|
+
- `light` - Clean light theme with gradients
|
|
172
|
+
- `dark` - Dark theme with pink/purple/blue gradients
|
|
173
|
+
- `solana-light` - Official Solana light theme (default)
|
|
174
|
+
- `solana-dark` - Official Solana dark theme
|
|
175
|
+
- `seeker` - Emerald/teal gradient theme
|
|
176
|
+
- `seeker-2` - Enhanced seeker theme with backdrop blur
|
|
177
|
+
- `terminal` - Retro terminal green-on-black theme
|
|
178
|
+
|
|
179
|
+
### Theme Example
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { X402Paywall } from '@payai/x402-solana-react';
|
|
183
|
+
import { useState } from 'react';
|
|
184
|
+
|
|
185
|
+
function PremiumPage() {
|
|
186
|
+
const [theme, setTheme] = useState('light');
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<X402Paywall
|
|
190
|
+
amount={0.02}
|
|
191
|
+
description="Premium Features"
|
|
192
|
+
network="solana"
|
|
193
|
+
theme={theme} // Try: 'light', 'dark', 'solana-light', 'solana-dark', etc.
|
|
194
|
+
onPaymentSuccess={(txId) => console.log('Paid!', txId)}
|
|
195
|
+
>
|
|
196
|
+
<AdvancedFeatures />
|
|
197
|
+
</X402Paywall>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Custom Styling
|
|
203
|
+
|
|
204
|
+
You can customize further using `classNames` and `customStyles` props:
|
|
108
205
|
|
|
109
206
|
```tsx
|
|
110
207
|
<X402Paywall
|
|
111
208
|
amount={5.00}
|
|
112
209
|
description="Premium Features"
|
|
113
|
-
|
|
114
|
-
theme="
|
|
210
|
+
network="solana"
|
|
211
|
+
theme="dark"
|
|
115
212
|
classNames={{
|
|
116
213
|
container: "bg-gradient-to-r from-purple-600 to-blue-600",
|
|
117
214
|
button: "bg-white text-purple-600 hover:bg-gray-50 font-bold"
|
|
@@ -130,19 +227,29 @@ The component comes with built-in Solana-themed styles. You can customize using
|
|
|
130
227
|
|
|
131
228
|
| Prop | Type | Required | Default | Description |
|
|
132
229
|
|------|------|----------|---------|-------------|
|
|
133
|
-
| `amount` | `number` | ✅ | - | Payment amount in
|
|
230
|
+
| `amount` | `number` | ✅ | - | Payment amount in USDC |
|
|
134
231
|
| `description` | `string` | ✅ | - | Payment description |
|
|
135
|
-
| `
|
|
136
|
-
| `network` | `'solana' \| 'solana-devnet'` | ❌ | `'solana-devnet'` |
|
|
137
|
-
| `
|
|
232
|
+
| `children` | `ReactNode` | ✅ | - | Protected content to show after payment |
|
|
233
|
+
| `network` | `'solana' \| 'solana-devnet'` | ❌ | `'solana-devnet'` | Solana network to use |
|
|
234
|
+
| `wallet` | `WalletAdapter` | ❌ | - | Optional wallet adapter (auto-uses context if not provided) |
|
|
235
|
+
| `rpcUrl` | `string` | ❌ | - | Custom RPC URL (recommended to avoid rate limits) |
|
|
236
|
+
| `autoSetupProviders` | `boolean` | ❌ | `true` | Automatically setup wallet providers |
|
|
237
|
+
| `providerNetwork` | `WalletAdapterNetwork` | ❌ | Auto-detected | Network for auto-setup providers |
|
|
238
|
+
| `providerEndpoint` | `string` | ❌ | - | Custom endpoint for auto-setup providers |
|
|
138
239
|
| `treasuryAddress` | `string` | ❌ | - | Custom treasury address |
|
|
139
240
|
| `facilitatorUrl` | `string` | ❌ | - | Custom facilitator URL |
|
|
140
|
-
| `theme` | `
|
|
141
|
-
| `showBalance` | `boolean` | ❌ | `true` | Show wallet balance |
|
|
142
|
-
| `showNetworkInfo` | `boolean` | ❌ | `true` | Show network
|
|
143
|
-
| `
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
241
|
+
| `theme` | `ThemePreset` | ❌ | `'solana-light'` | Visual theme (see Themes section) |
|
|
242
|
+
| `showBalance` | `boolean` | ❌ | `true` | Show wallet USDC balance |
|
|
243
|
+
| `showNetworkInfo` | `boolean` | ❌ | `true` | Show network information |
|
|
244
|
+
| `showPaymentDetails` | `boolean` | ❌ | `true` | Show payment details section |
|
|
245
|
+
| `maxPaymentAmount` | `number` | ❌ | - | Maximum allowed payment amount |
|
|
246
|
+
| `classNames` | `ComponentClassNames` | ❌ | - | Custom CSS classes for components |
|
|
247
|
+
| `customStyles` | `ComponentStyles` | ❌ | - | Custom inline styles for components |
|
|
248
|
+
| `onPaymentStart` | `() => void` | ❌ | - | Callback when payment starts |
|
|
249
|
+
| `onPaymentSuccess` | `(txId: string) => void` | ❌ | - | Callback on successful payment |
|
|
250
|
+
| `onPaymentError` | `(error: Error) => void` | ❌ | - | Callback on payment error |
|
|
251
|
+
| `onWalletConnect` | `(publicKey: string) => void` | ❌ | - | Callback when wallet connects |
|
|
252
|
+
| `onDisconnect` | `() => void` | ❌ | - | Callback when wallet disconnects |
|
|
146
253
|
|
|
147
254
|
See [full API documentation](./docs/API_REFERENCE.md) for complete reference.
|
|
148
255
|
|
|
@@ -160,7 +267,8 @@ npm install
|
|
|
160
267
|
|
|
161
268
|
# Copy environment variables
|
|
162
269
|
cp .env.example .env
|
|
163
|
-
# Edit .env and add your Helius
|
|
270
|
+
# Edit .env and add your custom RPC URL (Helius, QuickNode, etc.)
|
|
271
|
+
# Example: VITE_SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY
|
|
164
272
|
|
|
165
273
|
# Start development server
|
|
166
274
|
npm run dev
|
|
@@ -194,8 +302,10 @@ npm run lint
|
|
|
194
302
|
- Get devnet USDC from test token faucets like [Circle](https://faucet.circle.com/)
|
|
195
303
|
|
|
196
304
|
**"RPC rate limit exceeded"**
|
|
197
|
-
-
|
|
198
|
-
-
|
|
305
|
+
- Use a custom RPC provider (Helius, QuickNode, Alchemy)
|
|
306
|
+
- Set `VITE_SOLANA_RPC_URL` in `.env` file
|
|
307
|
+
- Pass via `rpcUrl` prop: `rpcUrl={import.meta.env.VITE_SOLANA_RPC_URL}`
|
|
308
|
+
- For production, always use a paid RPC endpoint
|
|
199
309
|
|
|
200
310
|
**"Transaction failed"**
|
|
201
311
|
- Verify network connectivity
|
|
@@ -203,8 +313,17 @@ npm run lint
|
|
|
203
313
|
- Ensure sufficient SOL for transaction fees
|
|
204
314
|
|
|
205
315
|
**Styling not working**
|
|
206
|
-
- Make sure you imported
|
|
316
|
+
- Make sure you imported both required stylesheets:
|
|
317
|
+
```tsx
|
|
318
|
+
import '@payai/x402-solana-react/styles';
|
|
319
|
+
import '@solana/wallet-adapter-react-ui/styles.css';
|
|
320
|
+
```
|
|
207
321
|
- Check browser console for CSS loading errors
|
|
322
|
+
- Verify Tailwind CSS is configured if using custom classes
|
|
323
|
+
|
|
324
|
+
**"process is not defined" error**
|
|
325
|
+
- Use Vite's `import.meta.env` instead of `process.env`
|
|
326
|
+
- Example: `import.meta.env.VITE_SOLANA_RPC_URL`
|
|
208
327
|
|
|
209
328
|
## ✅ Status
|
|
210
329
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payai/x402-solana-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Reusable React paywall components for Solana using the x402 payment protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"build": "tsc && vite build",
|
|
25
25
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
26
26
|
"preview": "vite preview",
|
|
27
|
-
"typecheck": "tsc --noEmit"
|
|
28
|
-
"postinstall": "patch-package"
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
29
28
|
},
|
|
30
29
|
"keywords": [
|
|
31
30
|
"x402",
|