facinet 2.2.2 → 2.4.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 +248 -244
- package/dist/browser.js +2773 -27534
- package/dist/browser.js.map +4 -4
- package/dist/commands/connect.d.ts.map +1 -1
- package/dist/commands/connect.js +7 -8
- package/dist/commands/connect.js.map +1 -1
- package/dist/commands/facilitator.d.ts +4 -15
- package/dist/commands/facilitator.d.ts.map +1 -1
- package/dist/commands/facilitator.js +40 -36
- package/dist/commands/facilitator.js.map +1 -1
- package/dist/commands/pay.d.ts +1 -8
- package/dist/commands/pay.d.ts.map +1 -1
- package/dist/commands/pay.js +47 -35
- package/dist/commands/pay.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +659 -92
- package/dist/index.js.map +7 -1
- package/dist/sdk/Facinet.d.ts +21 -5
- package/dist/sdk/Facinet.d.ts.map +1 -1
- package/dist/sdk/Facinet.js +165 -62
- package/dist/sdk/Facinet.js.map +1 -1
- package/dist/sdk/types.d.ts +8 -2
- package/dist/sdk/types.d.ts.map +1 -1
- package/dist/sdk.d.ts +1 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +386 -25
- package/dist/sdk.js.map +7 -1
- package/dist/sdk.mjs +140 -45
- package/dist/sdk.mjs.map +2 -2
- package/dist/utils/api.d.ts +18 -13
- package/dist/utils/api.d.ts.map +1 -1
- package/dist/utils/api.js +33 -40
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/config.d.ts +2 -9
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -1
- package/dist/utils/config.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
> JavaScript SDK and CLI tool for the x402 Facilitator Network
|
|
4
4
|
|
|
5
|
-
Make gasless USDC payments and manage facilitators on the x402 decentralized payment network
|
|
5
|
+
Make gasless USDC payments and manage facilitators on the x402 decentralized payment network. Now with **multichain support** across 4 testnets with **network-specific facilitator selection**.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Supported Chains
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- ⚡ **Fast** - Built on Avalanche for sub-second finality
|
|
9
|
+
| Chain | Network ID | Chain ID | Gas Token | Explorer | API URL |
|
|
10
|
+
|-------|-----------|----------|-----------|----------|---------|
|
|
11
|
+
| Avalanche Fuji | `avalanche-fuji` | 43113 | AVAX | testnet.snowtrace.io | x402-avalanche-chi.vercel.app |
|
|
12
|
+
| Ethereum Sepolia | `ethereum-sepolia` | 11155111 | ETH | sepolia.etherscan.io | x402-ethereum-chi.vercel.app |
|
|
13
|
+
| Base Sepolia | `base-sepolia` | 84532 | ETH | sepolia.basescan.org | x402-base-chi.vercel.app |
|
|
14
|
+
| Polygon Amoy | `polygon-amoy` | 80002 | MATIC | amoy.polygonscan.com | x402-polygon-chi.vercel.app |
|
|
16
15
|
|
|
17
16
|
## Installation
|
|
18
17
|
|
|
@@ -30,24 +29,30 @@ npm install -g facinet
|
|
|
30
29
|
|
|
31
30
|
## SDK Usage
|
|
32
31
|
|
|
32
|
+
### Network-Specific Facilitator Selection
|
|
33
|
+
|
|
34
|
+
The SDK automatically selects **active facilitators** for the **specific network** you're using. Each network has its own facilitator pool, and the SDK ensures you only get facilitators registered for that network.
|
|
35
|
+
|
|
33
36
|
### Browser (with MetaMask)
|
|
34
37
|
|
|
35
38
|
```typescript
|
|
36
39
|
import { Facinet } from 'facinet';
|
|
37
40
|
|
|
38
|
-
// Initialize SDK
|
|
41
|
+
// Initialize SDK for Base Sepolia network
|
|
39
42
|
const facinet = new Facinet({
|
|
40
|
-
network: '
|
|
43
|
+
network: 'base-sepolia', // SDK will use Base Sepolia API and facilitators
|
|
41
44
|
});
|
|
42
45
|
|
|
43
46
|
// Make a payment (MetaMask will prompt for signature)
|
|
44
47
|
const result = await facinet.pay({
|
|
45
|
-
amount: '1',
|
|
46
|
-
recipient: '0xYourMerchantAddress',
|
|
48
|
+
amount: '1',
|
|
49
|
+
recipient: '0xYourMerchantAddress',
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
console.log('Payment successful!', result.txHash);
|
|
50
|
-
console.log('Processed by:', result.facilitator.name);
|
|
53
|
+
console.log('Processed by:', result.facilitator.name); // Facilitator name
|
|
54
|
+
console.log('Facilitator ID:', result.facilitator.id);
|
|
55
|
+
console.log('Network:', result.payment.network); // 'base-sepolia'
|
|
51
56
|
```
|
|
52
57
|
|
|
53
58
|
### Node.js (with Private Key)
|
|
@@ -55,10 +60,10 @@ console.log('Processed by:', result.facilitator.name);
|
|
|
55
60
|
```typescript
|
|
56
61
|
import { Facinet } from 'facinet';
|
|
57
62
|
|
|
58
|
-
// Initialize with private key
|
|
63
|
+
// Initialize with private key on Polygon Amoy
|
|
59
64
|
const facinet = new Facinet({
|
|
60
65
|
privateKey: process.env.PRIVATE_KEY,
|
|
61
|
-
network: '
|
|
66
|
+
network: 'polygon-amoy', // SDK will use Polygon Amoy API and facilitators
|
|
62
67
|
});
|
|
63
68
|
|
|
64
69
|
// Make a payment
|
|
@@ -68,6 +73,7 @@ const result = await facinet.pay({
|
|
|
68
73
|
});
|
|
69
74
|
|
|
70
75
|
console.log('Transaction:', result.txHash);
|
|
76
|
+
console.log('Facilitator:', result.facilitator.name);
|
|
71
77
|
```
|
|
72
78
|
|
|
73
79
|
### Quick One-Liner
|
|
@@ -75,39 +81,156 @@ console.log('Transaction:', result.txHash);
|
|
|
75
81
|
```typescript
|
|
76
82
|
import { Facinet } from 'facinet';
|
|
77
83
|
|
|
78
|
-
// Quick payment
|
|
84
|
+
// Quick payment on Ethereum Sepolia
|
|
79
85
|
await Facinet.quickPay({
|
|
80
86
|
amount: '1',
|
|
81
87
|
recipient: '0xMerchantAddress',
|
|
82
88
|
privateKey: process.env.PRIVATE_KEY,
|
|
89
|
+
network: 'ethereum-sepolia', // Uses Ethereum Sepolia facilitators
|
|
83
90
|
});
|
|
84
91
|
```
|
|
85
92
|
|
|
86
|
-
### Get
|
|
93
|
+
### Get Active Facilitators for a Network
|
|
87
94
|
|
|
88
95
|
```typescript
|
|
89
|
-
|
|
96
|
+
import { Facinet } from 'facinet';
|
|
90
97
|
|
|
91
|
-
//
|
|
98
|
+
// Initialize for a specific network
|
|
99
|
+
const facinet = new Facinet({
|
|
100
|
+
network: 'base-sepolia', // Only gets facilitators for Base Sepolia
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Get all active facilitators for this network
|
|
92
104
|
const facilitators = await facinet.getFacilitators();
|
|
93
|
-
console.log(`${facilitators.length} active facilitators`);
|
|
105
|
+
console.log(`${facilitators.length} active facilitators on Base Sepolia`);
|
|
106
|
+
|
|
107
|
+
facilitators.forEach(fac => {
|
|
108
|
+
console.log(`- ${fac.name} (${fac.id})`);
|
|
109
|
+
console.log(` Wallet: ${fac.facilitatorWallet}`);
|
|
110
|
+
console.log(` Network: ${fac.network || 'N/A'}`);
|
|
111
|
+
console.log(` Chain ID: ${fac.chainId || 'N/A'}`);
|
|
112
|
+
console.log(` Status: ${fac.status}`);
|
|
113
|
+
});
|
|
94
114
|
|
|
95
|
-
// Get a random facilitator
|
|
115
|
+
// Get a random active facilitator for this network
|
|
96
116
|
const randomFacilitator = await facinet.selectRandomFacilitator();
|
|
97
117
|
console.log('Selected:', randomFacilitator.name);
|
|
118
|
+
console.log('Network:', randomFacilitator.network);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Network-Specific Examples
|
|
122
|
+
|
|
123
|
+
#### Avalanche Fuji
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const facinet = new Facinet({
|
|
127
|
+
network: 'avalanche-fuji', // Uses Avalanche Fuji facilitators
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const result = await facinet.pay({
|
|
131
|
+
amount: '1',
|
|
132
|
+
recipient: '0xYourMerchantAddress',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
console.log('Facilitator:', result.facilitator.name);
|
|
136
|
+
console.log('Network:', result.payment.network); // 'avalanche-fuji'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Ethereum Sepolia
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const facinet = new Facinet({
|
|
143
|
+
network: 'ethereum-sepolia', // Uses Ethereum Sepolia facilitators
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const facilitators = await facinet.getFacilitators();
|
|
147
|
+
// Only returns facilitators registered for Ethereum Sepolia (Chain ID: 11155111)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Base Sepolia
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const facinet = new Facinet({
|
|
154
|
+
network: 'base-sepolia', // Uses Base Sepolia facilitators
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const facilitator = await facinet.selectRandomFacilitator();
|
|
158
|
+
// Only selects from facilitators registered for Base Sepolia (Chain ID: 84532)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Polygon Amoy
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const facinet = new Facinet({
|
|
165
|
+
network: 'polygon-amoy', // Uses Polygon Amoy facilitators
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const result = await facinet.pay({
|
|
169
|
+
amount: '2',
|
|
170
|
+
recipient: '0xYourMerchantAddress',
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Get Supported Chains
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { Facinet } from 'facinet';
|
|
178
|
+
|
|
179
|
+
// List all supported chains
|
|
180
|
+
const chains = Facinet.getSupportedChains();
|
|
181
|
+
chains.forEach(chain => {
|
|
182
|
+
console.log(`${chain.displayName} (${chain.name})`);
|
|
183
|
+
console.log(` Chain ID: ${chain.chainId}`);
|
|
184
|
+
console.log(` Gas Token: ${chain.gasToken}`);
|
|
185
|
+
console.log(` USDC Address: ${chain.usdcAddress}`);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Get supported network names
|
|
189
|
+
const networks = Facinet.getSupportedNetworks();
|
|
190
|
+
console.log('Networks:', networks);
|
|
191
|
+
// ['avalanche-fuji', 'ethereum-sepolia', 'base-sepolia', 'polygon-amoy']
|
|
98
192
|
```
|
|
99
193
|
|
|
100
194
|
### SDK Configuration Options
|
|
101
195
|
|
|
102
196
|
```typescript
|
|
103
197
|
interface FacinetConfig {
|
|
104
|
-
apiUrl?: string; //
|
|
198
|
+
apiUrl?: string; // Optional: Override API URL (auto-selected by network)
|
|
105
199
|
privateKey?: string; // For Node.js (not needed in browser)
|
|
106
|
-
network?: 'avalanche' | 'ethereum' | '
|
|
200
|
+
network?: 'avalanche-fuji' | 'ethereum-sepolia' | 'base-sepolia' | 'polygon-amoy';
|
|
107
201
|
rpcUrl?: string; // Custom RPC URL (optional)
|
|
108
202
|
}
|
|
109
203
|
```
|
|
110
204
|
|
|
205
|
+
**Network-specific API URLs** (automatically selected):
|
|
206
|
+
- `avalanche-fuji` → `https://x402-avalanche-chi.vercel.app`
|
|
207
|
+
- `ethereum-sepolia` → `https://x402-ethereum-chi.vercel.app`
|
|
208
|
+
- `base-sepolia` → `https://x402-base-chi.vercel.app`
|
|
209
|
+
- `polygon-amoy` → `https://x402-polygon-chi.vercel.app`
|
|
210
|
+
|
|
211
|
+
**Legacy aliases** are supported for backwards compatibility:
|
|
212
|
+
- `'avalanche'` → `'avalanche-fuji'`
|
|
213
|
+
- `'ethereum'` → `'ethereum-sepolia'`
|
|
214
|
+
- `'polygon'` → `'polygon-amoy'`
|
|
215
|
+
- `'base'` → `'base-sepolia'`
|
|
216
|
+
|
|
217
|
+
### Facilitator Filtering
|
|
218
|
+
|
|
219
|
+
The SDK automatically filters facilitators by:
|
|
220
|
+
|
|
221
|
+
1. **Status**: Only `'active'` facilitators are selected
|
|
222
|
+
2. **Network**: Only facilitators registered for the selected network
|
|
223
|
+
3. **Chain ID**: Only facilitators matching the chain ID
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
const facinet = new Facinet({ network: 'base-sepolia' });
|
|
227
|
+
|
|
228
|
+
// This will only return facilitators that are:
|
|
229
|
+
// - Status: 'active'
|
|
230
|
+
// - Network: 'base-sepolia' OR Chain ID: 84532
|
|
231
|
+
const facilitators = await facinet.getFacilitators();
|
|
232
|
+
```
|
|
233
|
+
|
|
111
234
|
### TypeScript Support
|
|
112
235
|
|
|
113
236
|
Facinet is written in TypeScript and includes full type definitions:
|
|
@@ -117,17 +240,24 @@ import type {
|
|
|
117
240
|
FacinetConfig,
|
|
118
241
|
PaymentParams,
|
|
119
242
|
PaymentResult,
|
|
120
|
-
Facilitator
|
|
243
|
+
Facilitator,
|
|
244
|
+
ChainConfig
|
|
121
245
|
} from 'facinet';
|
|
122
246
|
|
|
123
247
|
const config: FacinetConfig = {
|
|
124
|
-
network: '
|
|
248
|
+
network: 'base-sepolia',
|
|
125
249
|
};
|
|
126
250
|
|
|
127
251
|
const params: PaymentParams = {
|
|
128
252
|
amount: '1',
|
|
129
253
|
recipient: '0x...',
|
|
130
254
|
};
|
|
255
|
+
|
|
256
|
+
// PaymentResult includes facilitator information
|
|
257
|
+
const result: PaymentResult = await facinet.pay(params);
|
|
258
|
+
console.log(result.facilitator.name); // Facilitator name
|
|
259
|
+
console.log(result.facilitator.id); // Facilitator ID
|
|
260
|
+
console.log(result.facilitator.wallet); // Facilitator wallet address
|
|
131
261
|
```
|
|
132
262
|
|
|
133
263
|
### React Example
|
|
@@ -139,11 +269,13 @@ import { Facinet } from 'facinet';
|
|
|
139
269
|
function PaymentButton() {
|
|
140
270
|
const [loading, setLoading] = useState(false);
|
|
141
271
|
const [txHash, setTxHash] = useState('');
|
|
272
|
+
const [facilitatorName, setFacilitatorName] = useState('');
|
|
273
|
+
const [network] = useState('base-sepolia');
|
|
142
274
|
|
|
143
275
|
const handlePayment = async () => {
|
|
144
276
|
setLoading(true);
|
|
145
277
|
try {
|
|
146
|
-
const facinet = new Facinet({ network
|
|
278
|
+
const facinet = new Facinet({ network });
|
|
147
279
|
|
|
148
280
|
const result = await facinet.pay({
|
|
149
281
|
amount: '1',
|
|
@@ -151,7 +283,8 @@ function PaymentButton() {
|
|
|
151
283
|
});
|
|
152
284
|
|
|
153
285
|
setTxHash(result.txHash);
|
|
154
|
-
|
|
286
|
+
setFacilitatorName(result.facilitator.name);
|
|
287
|
+
alert(`Payment successful! Processed by ${result.facilitator.name}`);
|
|
155
288
|
} catch (error) {
|
|
156
289
|
console.error('Payment failed:', error);
|
|
157
290
|
alert('Payment failed');
|
|
@@ -166,9 +299,11 @@ function PaymentButton() {
|
|
|
166
299
|
{loading ? 'Processing...' : 'Pay 1 USDC'}
|
|
167
300
|
</button>
|
|
168
301
|
{txHash && (
|
|
169
|
-
<
|
|
170
|
-
{txHash.slice(0, 10)}
|
|
171
|
-
|
|
302
|
+
<div>
|
|
303
|
+
<p>Transaction: {txHash.slice(0, 10)}...</p>
|
|
304
|
+
<p>Facilitator: {facilitatorName}</p>
|
|
305
|
+
<p>Network: {network}</p>
|
|
306
|
+
</div>
|
|
172
307
|
)}
|
|
173
308
|
</div>
|
|
174
309
|
);
|
|
@@ -177,13 +312,31 @@ function PaymentButton() {
|
|
|
177
312
|
|
|
178
313
|
### How SDK Payments Work
|
|
179
314
|
|
|
180
|
-
1. **Initialize SDK** - Create Facinet instance with your
|
|
181
|
-
2. **
|
|
182
|
-
3. **
|
|
183
|
-
4. **
|
|
184
|
-
5. **
|
|
315
|
+
1. **Initialize SDK** - Create Facinet instance with your network choice
|
|
316
|
+
2. **Network Detection** - SDK automatically uses the correct API URL for your network
|
|
317
|
+
3. **Active Facilitator Selection** - SDK picks a random **active** facilitator **for your network**
|
|
318
|
+
4. **Sign Authorization** - User signs ERC-3009 authorization (gasless!)
|
|
319
|
+
5. **Facilitator Executes** - Selected facilitator submits transaction and pays gas
|
|
320
|
+
6. **Payment Complete** - USDC transferred to YOUR merchant address
|
|
321
|
+
|
|
322
|
+
### Error Handling
|
|
185
323
|
|
|
186
|
-
|
|
324
|
+
```typescript
|
|
325
|
+
try {
|
|
326
|
+
const facinet = new Facinet({ network: 'base-sepolia' });
|
|
327
|
+
const result = await facinet.pay({
|
|
328
|
+
amount: '1',
|
|
329
|
+
recipient: '0xYourMerchantAddress',
|
|
330
|
+
});
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error.message.includes('No active facilitators available')) {
|
|
333
|
+
console.error('No active facilitators found for Base Sepolia');
|
|
334
|
+
console.error('Please check that facilitators are registered for this network');
|
|
335
|
+
} else {
|
|
336
|
+
console.error('Payment failed:', error.message);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
```
|
|
187
340
|
|
|
188
341
|
## CLI Usage
|
|
189
342
|
|
|
@@ -195,145 +348,50 @@ function PaymentButton() {
|
|
|
195
348
|
facinet connect
|
|
196
349
|
```
|
|
197
350
|
|
|
198
|
-
Choose to either:
|
|
199
|
-
- Enter your private key (for testing)
|
|
200
|
-
- Generate a new wallet
|
|
201
|
-
|
|
202
351
|
### 2. Make a Payment
|
|
203
352
|
|
|
204
353
|
```bash
|
|
354
|
+
# Pay on Avalanche Fuji (default)
|
|
205
355
|
facinet pay --amount 1 --to 0xRecipientAddress
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
The CLI will automatically:
|
|
209
|
-
- Select a random active facilitator
|
|
210
|
-
- Sign the payment authorization
|
|
211
|
-
- Submit to the facilitator network
|
|
212
|
-
- Show transaction details
|
|
213
|
-
|
|
214
|
-
### 3. List Active Facilitators
|
|
215
|
-
|
|
216
|
-
```bash
|
|
217
|
-
facinet facilitator list
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
See all active facilitators in the network with their stats.
|
|
221
356
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
facinet facilitator status fac_xyz123
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
View detailed information about a specific facilitator.
|
|
229
|
-
|
|
230
|
-
## Commands
|
|
231
|
-
|
|
232
|
-
### Connection
|
|
233
|
-
|
|
234
|
-
#### `facinet connect`
|
|
235
|
-
|
|
236
|
-
Connect your wallet to Facinet. Options:
|
|
237
|
-
- Enter existing private key
|
|
238
|
-
- Generate new wallet
|
|
239
|
-
|
|
240
|
-
Config is saved to `~/.facinet/config.json`
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
### Payment Commands
|
|
245
|
-
|
|
246
|
-
#### `facinet pay`
|
|
247
|
-
|
|
248
|
-
Make a payment via the x402 facilitator network.
|
|
249
|
-
|
|
250
|
-
**Options:**
|
|
251
|
-
- `-a, --amount <amount>` - Payment amount in USDC (default: 1)
|
|
252
|
-
- `-t, --to <address>` - Recipient Ethereum address
|
|
253
|
-
- `-c, --chain <chain>` - Blockchain network (default: avalanche)
|
|
254
|
-
- `-n, --network <url>` - Custom API URL
|
|
255
|
-
|
|
256
|
-
**Examples:**
|
|
257
|
-
|
|
258
|
-
```bash
|
|
259
|
-
# Pay 1 USDC to recipient
|
|
260
|
-
facinet pay --to 0x123...
|
|
261
|
-
|
|
262
|
-
# Pay custom amount
|
|
263
|
-
facinet pay --amount 5 --to 0x456...
|
|
357
|
+
# Pay on Base Sepolia (uses Base Sepolia facilitators)
|
|
358
|
+
facinet pay --amount 1 --to 0xRecipientAddress --chain base
|
|
264
359
|
|
|
265
|
-
#
|
|
266
|
-
facinet pay --to
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
---
|
|
270
|
-
|
|
271
|
-
### Facilitator Commands
|
|
272
|
-
|
|
273
|
-
#### `facinet facilitator create`
|
|
274
|
-
|
|
275
|
-
Create a new facilitator (requires 1 USDC registration fee).
|
|
360
|
+
# Pay on Polygon Amoy (uses Polygon Amoy facilitators)
|
|
361
|
+
facinet pay --amount 1 --to 0xRecipientAddress --chain polygon
|
|
276
362
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
- `-r, --recipient <address>` - Payment recipient address
|
|
280
|
-
- `-u, --url <url>` - API URL (default: http://localhost:3000)
|
|
281
|
-
|
|
282
|
-
**Example:**
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
facinet facilitator create --name "MyNode" --recipient 0xABC...
|
|
363
|
+
# Pay on Ethereum Sepolia (uses Ethereum Sepolia facilitators)
|
|
364
|
+
facinet pay --amount 1 --to 0xRecipientAddress --chain ethereum
|
|
286
365
|
```
|
|
287
366
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
#### `facinet facilitator list`
|
|
291
|
-
|
|
292
|
-
List all active facilitators in the network.
|
|
293
|
-
|
|
294
|
-
**Options:**
|
|
295
|
-
- `-u, --url <url>` - API URL (default: http://localhost:3000)
|
|
296
|
-
|
|
297
|
-
**Example:**
|
|
367
|
+
### 3. List Active Facilitators
|
|
298
368
|
|
|
299
369
|
```bash
|
|
370
|
+
# List all active facilitators (for the configured network)
|
|
300
371
|
facinet facilitator list
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
#### `facinet facilitator status <id>`
|
|
304
372
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
-
|
|
373
|
+
# The output shows:
|
|
374
|
+
# - Facilitator name
|
|
375
|
+
# - Facilitator ID
|
|
376
|
+
# - Wallet address
|
|
377
|
+
# - Status (active/inactive/needs_funding)
|
|
378
|
+
# - Network (if available)
|
|
379
|
+
# - Chain ID (if available)
|
|
380
|
+
# - Total payments processed
|
|
381
|
+
```
|
|
312
382
|
|
|
313
|
-
|
|
383
|
+
### 4. Check Facilitator Status
|
|
314
384
|
|
|
315
385
|
```bash
|
|
316
|
-
facinet facilitator status
|
|
386
|
+
facinet facilitator status fac_xyz123
|
|
317
387
|
```
|
|
318
388
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
Check the AVAX gas balance of a facilitator.
|
|
322
|
-
|
|
323
|
-
**Arguments:**
|
|
324
|
-
- `<id>` - Facilitator ID
|
|
325
|
-
|
|
326
|
-
**Options:**
|
|
327
|
-
- `-u, --url <url>` - API URL
|
|
328
|
-
|
|
329
|
-
**Example:**
|
|
389
|
+
### 5. Check Facilitator Balance
|
|
330
390
|
|
|
331
391
|
```bash
|
|
332
|
-
facinet facilitator balance
|
|
392
|
+
facinet facilitator balance fac_xyz123
|
|
333
393
|
```
|
|
334
394
|
|
|
335
|
-
---
|
|
336
|
-
|
|
337
395
|
## Configuration
|
|
338
396
|
|
|
339
397
|
Facinet stores configuration in `~/.facinet/config.json`:
|
|
@@ -343,31 +401,38 @@ Facinet stores configuration in `~/.facinet/config.json`:
|
|
|
343
401
|
"privateKey": "0x...",
|
|
344
402
|
"address": "0x...",
|
|
345
403
|
"network": "avalanche-fuji",
|
|
346
|
-
"apiUrl": "
|
|
404
|
+
"apiUrl": "https://x402-avalanche-chi.vercel.app"
|
|
347
405
|
}
|
|
348
406
|
```
|
|
349
407
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
- **Avalanche** (Fuji Testnet) - Default
|
|
353
|
-
- **Ethereum** (Sepolia Testnet)
|
|
354
|
-
- More chains coming soon
|
|
408
|
+
**Note**: The `apiUrl` is automatically set based on the `network` parameter. You can override it if needed.
|
|
355
409
|
|
|
356
410
|
## How It Works
|
|
357
411
|
|
|
358
|
-
|
|
412
|
+
### Network-Specific Facilitator Selection
|
|
413
|
+
|
|
414
|
+
1. **Network Selection** - You specify a network (e.g., `'base-sepolia'`)
|
|
415
|
+
2. **API URL Selection** - SDK automatically uses the correct API endpoint for that network
|
|
416
|
+
3. **Facilitator Filtering** - SDK fetches facilitators and filters by:
|
|
417
|
+
- Status: Must be `'active'`
|
|
418
|
+
- Network: Must match your selected network (if facilitator has `network` property)
|
|
419
|
+
- Chain ID: Must match your chain ID (if facilitator has `chainId` property)
|
|
420
|
+
4. **Random Selection** - SDK picks a random facilitator from the filtered list
|
|
421
|
+
5. **Payment Processing** - Selected facilitator processes your payment
|
|
422
|
+
|
|
423
|
+
### Payment Flow
|
|
424
|
+
|
|
425
|
+
1. **Random Selection** - SDK/CLI picks a random active facilitator from the **selected network**
|
|
359
426
|
2. **Sign Authorization** - You sign an ERC-3009 payment authorization (gasless for you!)
|
|
360
427
|
3. **Facilitator Executes** - The facilitator submits the transaction and pays gas
|
|
361
|
-
4. **Payment Complete** - USDC transferred on-chain
|
|
428
|
+
4. **Payment Complete** - USDC transferred on-chain
|
|
362
429
|
|
|
363
430
|
## Development
|
|
364
431
|
|
|
365
432
|
### Build from Source
|
|
366
433
|
|
|
367
434
|
```bash
|
|
368
|
-
|
|
369
|
-
git clone https://github.com/your-repo/x402.git
|
|
370
|
-
cd x402/packages/facinet
|
|
435
|
+
cd facinet-sdk
|
|
371
436
|
|
|
372
437
|
# Install dependencies
|
|
373
438
|
npm install
|
|
@@ -385,10 +450,10 @@ facinet --help
|
|
|
385
450
|
### Project Structure
|
|
386
451
|
|
|
387
452
|
```
|
|
388
|
-
facinet/
|
|
453
|
+
facinet-sdk/
|
|
389
454
|
├── src/
|
|
390
455
|
│ ├── sdk/
|
|
391
|
-
│ │ ├── Facinet.ts # Main SDK class
|
|
456
|
+
│ │ ├── Facinet.ts # Main SDK class (multichain with network-specific facilitators)
|
|
392
457
|
│ │ └── types.ts # TypeScript types
|
|
393
458
|
│ ├── commands/
|
|
394
459
|
│ │ ├── connect.ts # Wallet connection
|
|
@@ -396,96 +461,35 @@ facinet/
|
|
|
396
461
|
│ │ └── facilitator.ts # Facilitator management
|
|
397
462
|
│ ├── utils/
|
|
398
463
|
│ │ ├── config.ts # Configuration management
|
|
399
|
-
│ │ └── api.ts # API client
|
|
464
|
+
│ │ └── api.ts # API client with network filtering
|
|
400
465
|
│ ├── sdk.ts # SDK exports
|
|
401
466
|
│ └── index.ts # CLI entry point
|
|
402
467
|
├── dist/ # Compiled JavaScript
|
|
468
|
+
├── build.js # esbuild config
|
|
403
469
|
├── package.json
|
|
404
470
|
├── tsconfig.json
|
|
405
471
|
└── README.md
|
|
406
472
|
```
|
|
407
473
|
|
|
408
|
-
##
|
|
409
|
-
|
|
410
|
-
- **Private keys** are stored encrypted in `~/.facinet/config.json`
|
|
411
|
-
- **Never share** your private key or config file
|
|
412
|
-
- **Use test wallets** for testnet development
|
|
413
|
-
- **Backup** your private keys securely
|
|
414
|
-
|
|
415
|
-
## Troubleshooting
|
|
416
|
-
|
|
417
|
-
### "No wallet connected"
|
|
418
|
-
|
|
419
|
-
Run `facinet connect` first to set up your wallet.
|
|
420
|
-
|
|
421
|
-
### "No active facilitators available"
|
|
422
|
-
|
|
423
|
-
The network has no active facilitators. Create one with:
|
|
424
|
-
```bash
|
|
425
|
-
facinet facilitator create
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
### "Insufficient USDC"
|
|
429
|
-
|
|
430
|
-
You need USDC in your wallet. On testnet:
|
|
431
|
-
1. Get AVAX from faucet
|
|
432
|
-
2. Swap AVAX → USDC
|
|
433
|
-
|
|
434
|
-
### API connection errors
|
|
435
|
-
|
|
436
|
-
Check that your API URL is correct:
|
|
437
|
-
```bash
|
|
438
|
-
facinet pay --network https://your-api-url.com
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
## Examples
|
|
442
|
-
|
|
443
|
-
### Complete Payment Flow
|
|
444
|
-
|
|
445
|
-
```bash
|
|
446
|
-
# 1. Connect wallet
|
|
447
|
-
facinet connect
|
|
448
|
-
|
|
449
|
-
# 2. List available facilitators
|
|
450
|
-
facinet facilitator list
|
|
451
|
-
|
|
452
|
-
# 3. Make payment
|
|
453
|
-
facinet pay --amount 1 --to 0x1234567890123456789012345678901234567890
|
|
454
|
-
|
|
455
|
-
# Output:
|
|
456
|
-
# ✅ Payment processed successfully!
|
|
457
|
-
# Facilitator: Xavier
|
|
458
|
-
# Amount: 1 USDC
|
|
459
|
-
# Recipient: 0x123...
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Create and Monitor Facilitator
|
|
463
|
-
|
|
464
|
-
```bash
|
|
465
|
-
# 1. Create facilitator
|
|
466
|
-
facinet facilitator create --name "MyNode"
|
|
467
|
-
|
|
468
|
-
# 2. Fund with AVAX (send to facilitator wallet address)
|
|
469
|
-
# ...
|
|
474
|
+
## What's New in v2.4.0
|
|
470
475
|
|
|
471
|
-
|
|
472
|
-
|
|
476
|
+
- **Network-Specific Facilitator Selection** - SDK automatically filters facilitators by network/chainId
|
|
477
|
+
- **Network-Specific API URLs** - Each network uses its own API endpoint automatically
|
|
478
|
+
- **Enhanced Facilitator Filtering** - Only active facilitators for the selected network are returned
|
|
479
|
+
- **Better Error Messages** - Error messages now include network information
|
|
480
|
+
- **Facilitator Name Display** - Facilitator names are properly displayed in all results
|
|
481
|
+
- **Improved Documentation** - Comprehensive examples for each network
|
|
473
482
|
|
|
474
|
-
|
|
475
|
-
facinet facilitator balance fac_abc123
|
|
476
|
-
```
|
|
483
|
+
## Previous Versions
|
|
477
484
|
|
|
478
|
-
|
|
485
|
+
### v2.3.0
|
|
479
486
|
|
|
480
|
-
-
|
|
481
|
-
-
|
|
482
|
-
-
|
|
483
|
-
-
|
|
487
|
+
- **Multichain Support** - Now supports 4 chains: Avalanche Fuji, Ethereum Sepolia, Base Sepolia, Polygon Amoy
|
|
488
|
+
- **Chain-specific ERC-3009 domains** - Correct EIP-712 domain names per chain (USD Coin vs USDC)
|
|
489
|
+
- **Legacy aliases** - Old network names (`avalanche`, `ethereum`, `polygon`) still work
|
|
490
|
+
- **Static helpers** - `Facinet.getSupportedChains()` and `Facinet.getSupportedNetworks()`
|
|
491
|
+
- **`quickPay` with network** - Now accepts `network` parameter for chain selection
|
|
484
492
|
|
|
485
493
|
## License
|
|
486
494
|
|
|
487
495
|
MIT © x402 Team
|
|
488
|
-
|
|
489
|
-
---
|
|
490
|
-
|
|
491
|
-
**Built with x402 on Avalanche** ⚡
|