facinet 2.2.2 → 2.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 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 powered by Avalanche.
5
+ Make gasless USDC payments and manage facilitators on the x402 decentralized payment network. Now with **multichain support** across 4 testnets.
6
6
 
7
- ## Features
7
+ ## Supported Chains
8
8
 
9
- - 💳 **Make Payments** - Gasless USDC transfers via ERC-3009
10
- - 🎲 **Random Facilitator Selection** - Fair distribution across network
11
- - 🌐 **Multi-Platform** - Works in browser (MetaMask) and Node.js
12
- - 🚀 **Easy Integration** - Simple SDK for developers
13
- - 📊 **CLI Tool** - Command-line interface for payments and management
14
- - 🔐 **Secure** - Wallet management with encryption
15
- - ⚡ **Fast** - Built on Avalanche for sub-second finality
9
+ | Chain | Network ID | Gas Token | Explorer |
10
+ |-------|-----------|-----------|----------|
11
+ | Avalanche Fuji | `avalanche-fuji` | AVAX | testnet.snowtrace.io |
12
+ | Ethereum Sepolia | `ethereum-sepolia` | ETH | sepolia.etherscan.io |
13
+ | Base Sepolia | `base-sepolia` | ETH | sepolia.basescan.org |
14
+ | Polygon Amoy | `polygon-amoy` | MATIC | amoy.polygonscan.com |
16
15
 
17
16
  ## Installation
18
17
 
@@ -35,19 +34,20 @@ npm install -g facinet
35
34
  ```typescript
36
35
  import { Facinet } from 'facinet';
37
36
 
38
- // Initialize SDK
37
+ // Initialize SDK - choose your chain
39
38
  const facinet = new Facinet({
40
- network: 'avalanche', // or 'ethereum', 'polygon'
39
+ network: 'base-sepolia', // or 'avalanche-fuji', 'ethereum-sepolia', 'polygon-amoy'
41
40
  });
42
41
 
43
42
  // Make a payment (MetaMask will prompt for signature)
44
43
  const result = await facinet.pay({
45
- amount: '1', // Amount in USDC
46
- recipient: '0xYourMerchantAddress', // Where you want to receive payment
44
+ amount: '1',
45
+ recipient: '0xYourMerchantAddress',
47
46
  });
48
47
 
49
48
  console.log('Payment successful!', result.txHash);
50
49
  console.log('Processed by:', result.facilitator.name);
50
+ console.log('Network:', result.payment.network);
51
51
  ```
52
52
 
53
53
  ### Node.js (with Private Key)
@@ -55,10 +55,10 @@ console.log('Processed by:', result.facilitator.name);
55
55
  ```typescript
56
56
  import { Facinet } from 'facinet';
57
57
 
58
- // Initialize with private key
58
+ // Initialize with private key on Polygon Amoy
59
59
  const facinet = new Facinet({
60
60
  privateKey: process.env.PRIVATE_KEY,
61
- network: 'avalanche',
61
+ network: 'polygon-amoy',
62
62
  });
63
63
 
64
64
  // Make a payment
@@ -75,11 +75,12 @@ console.log('Transaction:', result.txHash);
75
75
  ```typescript
76
76
  import { Facinet } from 'facinet';
77
77
 
78
- // Quick payment without creating instance
78
+ // Quick payment on any chain
79
79
  await Facinet.quickPay({
80
80
  amount: '1',
81
81
  recipient: '0xMerchantAddress',
82
82
  privateKey: process.env.PRIVATE_KEY,
83
+ network: 'ethereum-sepolia',
83
84
  });
84
85
  ```
85
86
 
@@ -97,17 +98,40 @@ const randomFacilitator = await facinet.selectRandomFacilitator();
97
98
  console.log('Selected:', randomFacilitator.name);
98
99
  ```
99
100
 
101
+ ### Get Supported Chains
102
+
103
+ ```typescript
104
+ import { Facinet } from 'facinet';
105
+
106
+ // List all supported chains
107
+ const chains = Facinet.getSupportedChains();
108
+ chains.forEach(chain => {
109
+ console.log(`${chain.displayName} (${chain.name}) - Chain ID: ${chain.chainId}`);
110
+ });
111
+
112
+ // Get supported network names
113
+ const networks = Facinet.getSupportedNetworks();
114
+ console.log('Networks:', networks);
115
+ // ['avalanche-fuji', 'ethereum-sepolia', 'base-sepolia', 'polygon-amoy']
116
+ ```
117
+
100
118
  ### SDK Configuration Options
101
119
 
102
120
  ```typescript
103
121
  interface FacinetConfig {
104
122
  apiUrl?: string; // Default: 'https://x402-avalanche-chi.vercel.app'
105
123
  privateKey?: string; // For Node.js (not needed in browser)
106
- network?: 'avalanche' | 'ethereum' | 'polygon'; // Default: 'avalanche'
124
+ network?: 'avalanche-fuji' | 'ethereum-sepolia' | 'base-sepolia' | 'polygon-amoy';
107
125
  rpcUrl?: string; // Custom RPC URL (optional)
108
126
  }
109
127
  ```
110
128
 
129
+ **Legacy aliases** are supported for backwards compatibility:
130
+ - `'avalanche'` -> `'avalanche-fuji'`
131
+ - `'ethereum'` -> `'ethereum-sepolia'`
132
+ - `'polygon'` -> `'polygon-amoy'`
133
+ - `'base'` -> `'base-sepolia'`
134
+
111
135
  ### TypeScript Support
112
136
 
113
137
  Facinet is written in TypeScript and includes full type definitions:
@@ -117,11 +141,12 @@ import type {
117
141
  FacinetConfig,
118
142
  PaymentParams,
119
143
  PaymentResult,
120
- Facilitator
144
+ Facilitator,
145
+ ChainConfig
121
146
  } from 'facinet';
122
147
 
123
148
  const config: FacinetConfig = {
124
- network: 'avalanche',
149
+ network: 'base-sepolia',
125
150
  };
126
151
 
127
152
  const params: PaymentParams = {
@@ -139,11 +164,12 @@ import { Facinet } from 'facinet';
139
164
  function PaymentButton() {
140
165
  const [loading, setLoading] = useState(false);
141
166
  const [txHash, setTxHash] = useState('');
167
+ const [network] = useState('base-sepolia');
142
168
 
143
169
  const handlePayment = async () => {
144
170
  setLoading(true);
145
171
  try {
146
- const facinet = new Facinet({ network: 'avalanche' });
172
+ const facinet = new Facinet({ network });
147
173
 
148
174
  const result = await facinet.pay({
149
175
  amount: '1',
@@ -165,11 +191,7 @@ function PaymentButton() {
165
191
  <button onClick={handlePayment} disabled={loading}>
166
192
  {loading ? 'Processing...' : 'Pay 1 USDC'}
167
193
  </button>
168
- {txHash && (
169
- <p>Transaction: <a href={`https://testnet.snowtrace.io/tx/${txHash}`} target="_blank">
170
- {txHash.slice(0, 10)}...
171
- </a></p>
172
- )}
194
+ {txHash && <p>Transaction: {txHash.slice(0, 10)}...</p>}
173
195
  </div>
174
196
  );
175
197
  }
@@ -177,14 +199,12 @@ function PaymentButton() {
177
199
 
178
200
  ### How SDK Payments Work
179
201
 
180
- 1. **Initialize SDK** - Create Facinet instance with your config
202
+ 1. **Initialize SDK** - Create Facinet instance with your config and chain
181
203
  2. **Random Facilitator** - SDK automatically picks random active facilitator
182
204
  3. **Sign Authorization** - User signs ERC-3009 authorization (gasless!)
183
205
  4. **Facilitator Executes** - Facilitator submits transaction and pays gas
184
206
  5. **Payment Complete** - USDC transferred to YOUR merchant address
185
207
 
186
- **Key Point:** The `recipient` you specify in `pay()` is where YOU receive payment. The SDK automatically handles facilitator selection and gas payment.
187
-
188
208
  ## CLI Usage
189
209
 
190
210
  ### Quick Start
@@ -195,145 +215,34 @@ function PaymentButton() {
195
215
  facinet connect
196
216
  ```
197
217
 
198
- Choose to either:
199
- - Enter your private key (for testing)
200
- - Generate a new wallet
201
-
202
218
  ### 2. Make a Payment
203
219
 
204
220
  ```bash
221
+ # Pay on Avalanche (default)
205
222
  facinet pay --amount 1 --to 0xRecipientAddress
206
- ```
207
223
 
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
224
+ # Pay on Base Sepolia
225
+ facinet pay --amount 1 --to 0xRecipientAddress --chain base
213
226
 
214
- ### 3. List Active Facilitators
227
+ # Pay on Polygon Amoy
228
+ facinet pay --amount 1 --to 0xRecipientAddress --chain polygon
215
229
 
216
- ```bash
217
- facinet facilitator list
230
+ # Pay on Ethereum Sepolia
231
+ facinet pay --amount 1 --to 0xRecipientAddress --chain ethereum
218
232
  ```
219
233
 
220
- See all active facilitators in the network with their stats.
221
-
222
- ### 4. Check Facilitator Status
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...
264
-
265
- # Use custom API endpoint
266
- facinet pay --to 0x789... --network https://my-api.com
267
- ```
268
-
269
- ---
270
-
271
- ### Facilitator Commands
272
-
273
- #### `facinet facilitator create`
274
-
275
- Create a new facilitator (requires 1 USDC registration fee).
276
-
277
- **Options:**
278
- - `-n, --name <name>` - Facilitator name
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...
286
- ```
287
-
288
- **Important:** Save the facilitator wallet private key shown after creation!
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:**
234
+ ### 3. List Active Facilitators
298
235
 
299
236
  ```bash
300
237
  facinet facilitator list
301
238
  ```
302
239
 
303
- #### `facinet facilitator status <id>`
304
-
305
- Check the status of a specific facilitator.
306
-
307
- **Arguments:**
308
- - `<id>` - Facilitator ID (e.g., fac_xyz123)
309
-
310
- **Options:**
311
- - `-u, --url <url>` - API URL
312
-
313
- **Example:**
314
-
315
- ```bash
316
- facinet facilitator status fac_NdIk4EytdaIYHRK1
317
- ```
318
-
319
- #### `facinet facilitator balance <id>`
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:**
240
+ ### 4. Check Facilitator Status
330
241
 
331
242
  ```bash
332
- facinet facilitator balance fac_NdIk4EytdaIYHRK1
243
+ facinet facilitator status fac_xyz123
333
244
  ```
334
245
 
335
- ---
336
-
337
246
  ## Configuration
338
247
 
339
248
  Facinet stores configuration in `~/.facinet/config.json`:
@@ -343,31 +252,23 @@ Facinet stores configuration in `~/.facinet/config.json`:
343
252
  "privateKey": "0x...",
344
253
  "address": "0x...",
345
254
  "network": "avalanche-fuji",
346
- "apiUrl": "http://localhost:3000"
255
+ "apiUrl": "https://x402-avalanche-chi.vercel.app"
347
256
  }
348
257
  ```
349
258
 
350
- ## Supported Networks
351
-
352
- - **Avalanche** (Fuji Testnet) - Default
353
- - **Ethereum** (Sepolia Testnet)
354
- - More chains coming soon
355
-
356
259
  ## How It Works
357
260
 
358
- 1. **Random Selection** - CLI picks a random active facilitator from the network
261
+ 1. **Random Selection** - SDK/CLI picks a random active facilitator from the network
359
262
  2. **Sign Authorization** - You sign an ERC-3009 payment authorization (gasless for you!)
360
263
  3. **Facilitator Executes** - The facilitator submits the transaction and pays gas
361
- 4. **Payment Complete** - USDC transferred on-chain, access granted
264
+ 4. **Payment Complete** - USDC transferred on-chain
362
265
 
363
266
  ## Development
364
267
 
365
268
  ### Build from Source
366
269
 
367
270
  ```bash
368
- # Clone repository
369
- git clone https://github.com/your-repo/x402.git
370
- cd x402/packages/facinet
271
+ cd facinet-sdk
371
272
 
372
273
  # Install dependencies
373
274
  npm install
@@ -385,10 +286,10 @@ facinet --help
385
286
  ### Project Structure
386
287
 
387
288
  ```
388
- facinet/
289
+ facinet-sdk/
389
290
  ├── src/
390
291
  │ ├── sdk/
391
- │ │ ├── Facinet.ts # Main SDK class
292
+ │ │ ├── Facinet.ts # Main SDK class (multichain)
392
293
  │ │ └── types.ts # TypeScript types
393
294
  │ ├── commands/
394
295
  │ │ ├── connect.ts # Wallet connection
@@ -400,92 +301,20 @@ facinet/
400
301
  │ ├── sdk.ts # SDK exports
401
302
  │ └── index.ts # CLI entry point
402
303
  ├── dist/ # Compiled JavaScript
304
+ ├── build.js # esbuild config
403
305
  ├── package.json
404
306
  ├── tsconfig.json
405
307
  └── README.md
406
308
  ```
407
309
 
408
- ## Security
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
- ```
310
+ ## What's New in v2.3.0
427
311
 
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
- # ...
470
-
471
- # 3. Check status
472
- facinet facilitator status fac_abc123
473
-
474
- # 4. Monitor balance
475
- facinet facilitator balance fac_abc123
476
- ```
477
-
478
- ## Resources
479
-
480
- - [x402 Protocol](https://github.com/x402-rs/x402-rs)
481
- - [Documentation](https://docs.x402.network)
482
- - [Avalanche Docs](https://docs.avax.network/)
483
- - [Report Issues](https://github.com/your-repo/x402/issues)
312
+ - **Multichain Support** - Now supports 4 chains: Avalanche Fuji, Ethereum Sepolia, Base Sepolia, Polygon Amoy
313
+ - **Chain-specific ERC-3009 domains** - Correct EIP-712 domain names per chain (USD Coin vs USDC)
314
+ - **Legacy aliases** - Old network names (`avalanche`, `ethereum`, `polygon`) still work
315
+ - **Static helpers** - `Facinet.getSupportedChains()` and `Facinet.getSupportedNetworks()`
316
+ - **`quickPay` with network** - Now accepts `network` parameter for chain selection
484
317
 
485
318
  ## License
486
319
 
487
320
  MIT © x402 Team
488
-
489
- ---
490
-
491
- **Built with x402 on Avalanche** ⚡