facinet 1.0.0 → 2.0.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 CHANGED
@@ -1,25 +1,193 @@
1
- # Facinet CLI
1
+ # Facinet
2
2
 
3
- > Command-line tool for the x402 Facilitator Network
3
+ > JavaScript SDK and CLI tool for the x402 Facilitator Network
4
4
 
5
- Make 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 powered by Avalanche.
6
6
 
7
7
  ## Features
8
8
 
9
- - 💳 **Make Payments** - Pay via x402 using gasless USDC transfers
9
+ - 💳 **Make Payments** - Gasless USDC transfers via ERC-3009
10
10
  - 🎲 **Random Facilitator Selection** - Fair distribution across network
11
- - 🚀 **Create Facilitators** - Set up your own payment facilitator
12
- - 📊 **Manage & Monitor** - Check status, balance, and activity
13
- - 🔐 **Secure** - Local wallet management with encryption
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
14
15
  - ⚡ **Fast** - Built on Avalanche for sub-second finality
15
16
 
16
17
  ## Installation
17
18
 
19
+ ### As a Library (SDK)
20
+
21
+ ```bash
22
+ npm install facinet
23
+ ```
24
+
25
+ ### As a CLI Tool
26
+
18
27
  ```bash
19
28
  npm install -g facinet
20
29
  ```
21
30
 
22
- ## Quick Start
31
+ ## SDK Usage
32
+
33
+ ### Browser (with MetaMask)
34
+
35
+ ```typescript
36
+ import { Facinet } from 'facinet';
37
+
38
+ // Initialize SDK
39
+ const facinet = new Facinet({
40
+ network: 'avalanche', // or 'ethereum', 'polygon'
41
+ });
42
+
43
+ // Make a payment (MetaMask will prompt for signature)
44
+ const result = await facinet.pay({
45
+ amount: '1', // Amount in USDC
46
+ recipient: '0xYourMerchantAddress', // Where you want to receive payment
47
+ });
48
+
49
+ console.log('Payment successful!', result.txHash);
50
+ console.log('Processed by:', result.facilitator.name);
51
+ ```
52
+
53
+ ### Node.js (with Private Key)
54
+
55
+ ```typescript
56
+ import { Facinet } from 'facinet';
57
+
58
+ // Initialize with private key
59
+ const facinet = new Facinet({
60
+ privateKey: process.env.PRIVATE_KEY,
61
+ network: 'avalanche',
62
+ });
63
+
64
+ // Make a payment
65
+ const result = await facinet.pay({
66
+ amount: '5',
67
+ recipient: '0xYourMerchantAddress',
68
+ });
69
+
70
+ console.log('Transaction:', result.txHash);
71
+ ```
72
+
73
+ ### Quick One-Liner
74
+
75
+ ```typescript
76
+ import { Facinet } from 'facinet';
77
+
78
+ // Quick payment without creating instance
79
+ await Facinet.quickPay({
80
+ amount: '1',
81
+ recipient: '0xMerchantAddress',
82
+ privateKey: process.env.PRIVATE_KEY,
83
+ });
84
+ ```
85
+
86
+ ### Get Available Facilitators
87
+
88
+ ```typescript
89
+ const facinet = new Facinet();
90
+
91
+ // Get all active facilitators
92
+ const facilitators = await facinet.getFacilitators();
93
+ console.log(`${facilitators.length} active facilitators`);
94
+
95
+ // Get a random facilitator
96
+ const randomFacilitator = await facinet.selectRandomFacilitator();
97
+ console.log('Selected:', randomFacilitator.name);
98
+ ```
99
+
100
+ ### SDK Configuration Options
101
+
102
+ ```typescript
103
+ interface FacinetConfig {
104
+ apiUrl?: string; // Default: 'https://x402-avalanche-chi.vercel.app'
105
+ privateKey?: string; // For Node.js (not needed in browser)
106
+ network?: 'avalanche' | 'ethereum' | 'polygon'; // Default: 'avalanche'
107
+ rpcUrl?: string; // Custom RPC URL (optional)
108
+ }
109
+ ```
110
+
111
+ ### TypeScript Support
112
+
113
+ Facinet is written in TypeScript and includes full type definitions:
114
+
115
+ ```typescript
116
+ import type {
117
+ FacinetConfig,
118
+ PaymentParams,
119
+ PaymentResult,
120
+ Facilitator
121
+ } from 'facinet';
122
+
123
+ const config: FacinetConfig = {
124
+ network: 'avalanche',
125
+ };
126
+
127
+ const params: PaymentParams = {
128
+ amount: '1',
129
+ recipient: '0x...',
130
+ };
131
+ ```
132
+
133
+ ### React Example
134
+
135
+ ```tsx
136
+ import { useState } from 'react';
137
+ import { Facinet } from 'facinet';
138
+
139
+ function PaymentButton() {
140
+ const [loading, setLoading] = useState(false);
141
+ const [txHash, setTxHash] = useState('');
142
+
143
+ const handlePayment = async () => {
144
+ setLoading(true);
145
+ try {
146
+ const facinet = new Facinet({ network: 'avalanche' });
147
+
148
+ const result = await facinet.pay({
149
+ amount: '1',
150
+ recipient: '0xYourMerchantAddress',
151
+ });
152
+
153
+ setTxHash(result.txHash);
154
+ alert('Payment successful!');
155
+ } catch (error) {
156
+ console.error('Payment failed:', error);
157
+ alert('Payment failed');
158
+ } finally {
159
+ setLoading(false);
160
+ }
161
+ };
162
+
163
+ return (
164
+ <div>
165
+ <button onClick={handlePayment} disabled={loading}>
166
+ {loading ? 'Processing...' : 'Pay 1 USDC'}
167
+ </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
+ )}
173
+ </div>
174
+ );
175
+ }
176
+ ```
177
+
178
+ ### How SDK Payments Work
179
+
180
+ 1. **Initialize SDK** - Create Facinet instance with your config
181
+ 2. **Random Facilitator** - SDK automatically picks random active facilitator
182
+ 3. **Sign Authorization** - User signs ERC-3009 authorization (gasless!)
183
+ 4. **Facilitator Executes** - Facilitator submits transaction and pays gas
184
+ 5. **Payment Complete** - USDC transferred to YOUR merchant address
185
+
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
+ ## CLI Usage
189
+
190
+ ### Quick Start
23
191
 
24
192
  ### 1. Connect Your Wallet
25
193
 
@@ -219,6 +387,9 @@ facinet --help
219
387
  ```
220
388
  facinet/
221
389
  ├── src/
390
+ │ ├── sdk/
391
+ │ │ ├── Facinet.ts # Main SDK class
392
+ │ │ └── types.ts # TypeScript types
222
393
  │ ├── commands/
223
394
  │ │ ├── connect.ts # Wallet connection
224
395
  │ │ ├── pay.ts # Payment processing
@@ -226,7 +397,9 @@ facinet/
226
397
  │ ├── utils/
227
398
  │ │ ├── config.ts # Configuration management
228
399
  │ │ └── api.ts # API client
400
+ │ ├── sdk.ts # SDK exports
229
401
  │ └── index.ts # CLI entry point
402
+ ├── dist/ # Compiled JavaScript
230
403
  ├── package.json
231
404
  ├── tsconfig.json
232
405
  └── README.md