moltspay 0.8.15 โ†’ 0.9.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
@@ -1,19 +1,16 @@
1
1
  # MoltsPay
2
2
 
3
- Blockchain payment infrastructure for AI Agents on Moltbook.
3
+ Blockchain payment infrastructure for AI Agents. Turn any skill into a paid service with one JSON file.
4
4
 
5
5
  ## Features
6
6
 
7
- - ๐ŸŽซ **Invoice Generation** - Create standardized payment requests
8
- - โœ… **Payment Verification** - Verify on-chain USDC transfers
9
- - ๐Ÿ’ณ **Custody Wallet** - Manage USDC transfers
7
+ - ๐Ÿ”Œ **Skill Integration** - Add `moltspay.services.json` to any existing skill
8
+ - ๐ŸŽซ **x402 Protocol** - HTTP-native payments (402 Payment Required)
9
+ - ๐Ÿ’จ **Gasless** - Both client and server pay no gas (CDP facilitator handles it)
10
+ - โœ… **Payment Verification** - Automatic on-chain verification
10
11
  - ๐Ÿ”’ **Secure Wallet** - Limits, whitelist, and audit logging
11
- - ๐Ÿ“ **EIP-2612 Permit** - Gasless user payments
12
12
  - โ›“๏ธ **Multi-chain** - Base, Polygon, Ethereum (mainnet & testnet)
13
13
  - ๐Ÿค– **Agent-to-Agent** - Complete A2A payment flow support
14
- - ๐Ÿงพ **Receipt Generation** - Transaction receipts for audit/accounting
15
- - ๐Ÿ”„ **x402 Protocol** - HTTP-native payments (v0.4.0+)
16
- - ๐Ÿฆ **CDP Wallet** - Coinbase Developer Platform integration (v0.4.0+)
17
14
 
18
15
  ## Installation
19
16
 
@@ -23,582 +20,237 @@ npm install moltspay@latest
23
20
 
24
21
  ## Quick Start
25
22
 
26
- ```typescript
27
- import { PaymentAgent, SecureWallet } from 'moltspay';
28
-
29
- // Initialize payment agent
30
- const agent = new PaymentAgent({
31
- chain: 'base',
32
- walletAddress: '0x...',
33
- });
34
-
35
- // Generate invoice
36
- const invoice = agent.createInvoice({
37
- orderId: 'order_123',
38
- amount: 2.0,
39
- service: 'video_generation',
40
- });
23
+ ### For Service Providers (Selling)
41
24
 
42
- // Verify payment
43
- const result = await agent.verifyPayment(txHash);
44
- if (result.verified) {
45
- console.log('Payment confirmed!');
25
+ **1. Have an existing skill with exported functions:**
26
+ ```javascript
27
+ // index.js (your existing skill)
28
+ export async function textToVideo({ prompt }) {
29
+ // your implementation
30
+ return { video_url: "https://..." };
46
31
  }
47
32
  ```
48
33
 
49
- ## Usage with AI Agents
50
-
51
- Payment Agent is designed to be called by AI Agents (like Clawdbot) to handle payment logic:
52
-
53
- ```
54
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
55
- โ”‚ Bot (Clawdbot) โ”‚
56
- โ”‚ โ€ข Business logic โ”‚
57
- โ”‚ โ€ข User interaction โ”‚
58
- โ”‚ โ€ข Service delivery โ”‚
59
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
60
- โ†“ calls
61
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
62
- โ”‚ Payment Agent (this package) โ”‚
63
- โ”‚ โ€ข Invoice generation โ”‚
64
- โ”‚ โ€ข Payment verification โ”‚
65
- โ”‚ โ€ข Wallet management โ”‚
66
- โ”‚ โ€ข Security controls โ”‚
67
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
68
- โ†“
69
- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
70
- โ”‚ Blockchain โ”‚
71
- โ”‚ (Base / Polygon / Ethereum) โ”‚
72
- โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
34
+ **2. Add `moltspay.services.json`:**
35
+ ```json
36
+ {
37
+ "provider": {
38
+ "name": "My Video Service",
39
+ "wallet": "0xYOUR_WALLET_ADDRESS"
40
+ },
41
+ "services": [{
42
+ "id": "text-to-video",
43
+ "function": "textToVideo",
44
+ "price": 0.99,
45
+ "currency": "USDC"
46
+ }]
47
+ }
73
48
  ```
74
49
 
75
- ## Agent-to-Agent Payment Flow (v0.2.0+)
76
-
77
- Complete support for pure-conversation payment between AI Agents.
78
-
79
- ### Flow Overview
80
-
81
- ```
82
- START โ†’ ่ƒฝๅŠ›่ฏ†ๅˆซ โ†’ ่ƒฝๅŠ›ๅๅ•† โ†’ Onboarding โ†’ ๆœๅŠก่ฏทๆฑ‚ โ†’ ๆŠฅไปท โ†’ ๆ”ฏไป˜ โ†’ ้ชŒ่ฏ โ†’ ไบคไป˜ โ†’ ๆ”ถๆฎ โ†’ END
50
+ **3. Start server:**
51
+ ```bash
52
+ npx moltspay start ./my-skill --port 3000
83
53
  ```
84
54
 
85
- ### Client Agent: Auto-Setup (Recommended - v0.2.5+)
55
+ That's it! Your skill now accepts x402 payments.
86
56
 
87
- The simplest way for a client agent to get started:
57
+ ### For Clients (Buying)
88
58
 
89
- **First-time setup is automatic:**
59
+ **1. Initialize wallet (one time):**
90
60
  ```bash
91
- # 1. Install (agent does this automatically when calling a paid service)
92
- npm install moltspay
93
-
94
- # 2. Initialize wallet (automatic, no gas needed)
95
61
  npx moltspay init --chain base
96
-
97
- # Output:
98
- # โœ… Agent wallet initialized
99
- # Address: 0xABC123...
100
- # Storage: ~/.moltspay
62
+ # Output: Wallet address 0xABC123...
101
63
  ```
102
64
 
103
- **Owner funds the Agent (one-time):**
104
- - Agent tells Owner its wallet address
105
- - Owner sends USDC to the agent's address using Coinbase, MetaMask, etc.
106
- - No complex signatures needed โ€” just a simple transfer
65
+ **2. Fund your wallet:**
66
+ Ask your owner to send USDC to your wallet address. No ETH needed!
107
67
 
108
- **Agent pays for services:**
68
+ **3. Use paid services:**
109
69
  ```bash
110
- npx moltspay transfer --to 0xSERVICE_PROVIDER --amount 0.99 --chain base
70
+ npx moltspay pay https://server.com text-to-video --prompt "a cat dancing"
111
71
  ```
112
72
 
113
- ### Code Example (Auto-Initialize)
114
-
115
- ```typescript
116
- import { AgentWallet } from 'moltspay';
117
-
118
- // Auto-creates wallet on first use (no gas needed)
119
- const wallet = new AgentWallet({ chain: 'base' });
120
- console.log('Agent address:', wallet.address);
121
- // Tell Owner to send USDC to this address
73
+ ## Skill Structure
122
74
 
123
- // Check balance
124
- const balance = await wallet.getBalance();
125
- console.log('USDC balance:', balance.usdc);
75
+ MoltsPay reads your skill's existing structure:
126
76
 
127
- // Pay for services
128
- const result = await wallet.transfer({
129
- to: '0xServiceProvider...',
130
- amount: 0.99,
131
- });
132
- console.log('Paid:', result.txHash);
133
77
  ```
134
-
135
- ### Buyer Agent: Create Wallet & Pay (Manual)
136
-
137
- For more control, you can manually manage wallet creation:
138
-
139
- ```typescript
140
- import { createWallet, loadWallet, PermitWallet } from 'moltspay';
141
-
142
- // Step 1: Create wallet (first time)
143
- const result = createWallet({ password: 'secure123' });
144
- console.log('Wallet address:', result.address);
145
- // Send this address to Boss for Permit authorization
146
-
147
- // Step 2: After Boss signs Permit, load wallet and pay
148
- const { privateKey } = loadWallet({ password: 'secure123' });
149
- const wallet = new PermitWallet({
150
- chain: 'base',
151
- privateKey
152
- });
153
-
154
- // Step 3: Pay using Boss's Permit
155
- const payment = await wallet.transferWithPermit({
156
- to: '0xSELLER...',
157
- amount: 3.99,
158
- permit: bossSignedPermit // { owner, spender, value, deadline, v, r, s }
159
- });
160
-
161
- console.log('Payment tx:', payment.tx_hash);
78
+ my-skill/
79
+ โ”œโ”€โ”€ package.json # MoltsPay reads "main" field
80
+ โ”œโ”€โ”€ index.js # Your existing exports
81
+ โ””โ”€โ”€ moltspay.services.json # Only file you add!
162
82
  ```
163
83
 
164
- ### Seller Agent: Verify & Deliver
84
+ **Entry point discovery:**
85
+ 1. If `package.json` exists โ†’ uses `main` field
86
+ 2. Otherwise โ†’ defaults to `index.js`
165
87
 
166
- ```typescript
167
- import {
168
- PaymentAgent,
169
- generateReceipt,
170
- formatReceiptText,
171
- SellerTemplates
172
- } from 'moltspay';
173
-
174
- const agent = new PaymentAgent({
175
- chain: 'base',
176
- walletAddress: '0xSELLER...',
177
- });
88
+ **Your functions stay untouched.** Just add the JSON config.
178
89
 
179
- // Step 1: Create invoice & quote
180
- const invoice = agent.createInvoice({
181
- orderId: 'vo_123',
182
- amount: 3.99,
183
- service: 'Video Generation 5s 720p',
184
- });
90
+ ## Services Manifest Schema
185
91
 
186
- // Use template for natural conversation
187
- console.log(SellerTemplates.quote({
188
- service: 'Video Generation 5s 720p',
189
- price: 3.99,
190
- recipientAddress: agent.walletAddress,
191
- }));
192
-
193
- // Step 2: Verify payment
194
- const result = await agent.verifyPayment(txHash, { expectedAmount: 3.99 });
195
-
196
- if (result.verified) {
197
- console.log(SellerTemplates.verificationPassed(result.amount!));
198
-
199
- // Step 3: Deliver service
200
- // ... generate video ...
201
-
202
- // Step 4: Generate receipt
203
- const receipt = generateReceipt({
204
- orderId: 'vo_123',
205
- service: 'Video Generation 5s 720p',
206
- amount: 3.99,
207
- chain: 'base',
208
- txHash: result.tx_hash!,
209
- payerAddress: result.from!,
210
- recipientAddress: agent.walletAddress,
211
- delivery: {
212
- url: 'https://download.link/video.mp4',
213
- fileHash: 'sha256:abc123...',
92
+ ```json
93
+ {
94
+ "$schema": "https://moltspay.com/schemas/services.json",
95
+ "provider": {
96
+ "name": "Service Name",
97
+ "description": "Optional description",
98
+ "wallet": "0x...",
99
+ "chain": "base"
100
+ },
101
+ "services": [{
102
+ "id": "service-id",
103
+ "name": "Human Readable Name",
104
+ "description": "What it does",
105
+ "function": "exportedFunctionName",
106
+ "price": 0.99,
107
+ "currency": "USDC",
108
+ "input": {
109
+ "prompt": { "type": "string", "required": true }
214
110
  },
215
- });
216
-
217
- console.log(formatReceiptText(receipt));
111
+ "output": {
112
+ "result_url": { "type": "string" }
113
+ }
114
+ }]
218
115
  }
219
116
  ```
220
117
 
221
- ### Conversation Templates
222
-
223
- Standard templates for natural A2A dialogue:
224
-
225
- ```typescript
226
- import { SellerTemplates, BuyerTemplates, parseStatusMarker } from 'moltspay';
227
-
228
- // Seller templates
229
- SellerTemplates.askPaymentCapability() // "Do you have USDC payment capability?"
230
- SellerTemplates.guideInstall() // "Install moltspay and init wallet..."
231
- SellerTemplates.guideFunding(agentAddr, 10) // "Ask Owner to send USDC to your wallet"
232
- SellerTemplates.quote({ service, price, recipientAddress })
233
- SellerTemplates.verificationPassed(amount)
234
- SellerTemplates.deliver({ downloadUrl, fileHash })
235
- SellerTemplates.receipt(receipt)
236
-
237
- // Buyer templates
238
- BuyerTemplates.requestService('video generation')
239
- BuyerTemplates.noCapability() // "I don't have a wallet"
240
- BuyerTemplates.walletCreated(address) // "[status:wallet_ready]"
241
- BuyerTemplates.fundingReceived(10) // "[status:funded USDC=10]"
242
- BuyerTemplates.requestFunding(addr, 10) // "Owner, please send USDC to my wallet"
243
- BuyerTemplates.paymentSent(txHash, amount) // "[status:payment_sent tx=...]"
244
-
245
- // Parse status markers from messages
246
- const status = parseStatusMarker('[status:payment_sent tx=0xabc amount=3.99 USDC]');
247
- // { type: 'payment_sent', data: { txHash: '0xabc', amount: '3.99' } }
248
- ```
249
-
250
- ## x402 Protocol Support (v0.4.0+)
251
-
252
- x402 is an open standard for HTTP-native payments. When a server returns 402 Payment Required, the client can pay and retry automatically.
253
-
254
- **Key benefit: Client agents need NO gas!** x402 uses EIP-3009 signatures - the client only signs, and Coinbase's facilitator executes on-chain (paying gas).
255
-
256
- ### Client Agent Setup (Simple, No Gas Needed)
257
-
258
- ```bash
259
- # 1. Initialize wallet (generates local keypair)
260
- npx moltspay init --chain base
261
-
262
- # Output:
263
- # โœ… Local wallet initialized
264
- # Address: 0xABC123...
265
- # Storage: ~/.moltspay
266
- ```
118
+ ### Validate Your Config
267
119
 
268
120
  ```bash
269
- # 2. Tell your owner to send USDC to your address
270
- # Owner sends USDC via Coinbase/MetaMask - just a normal transfer
271
- # NO ETH/gas needed in your wallet!
121
+ npx moltspay validate ./my-skill
122
+ # or
123
+ npx moltspay validate ./moltspay.services.json
272
124
  ```
273
125
 
274
- ```typescript
275
- // 3. Make paid requests - payment handled automatically
276
- import { createX402Client } from 'moltspay';
277
-
278
- const client = await createX402Client({ chain: 'base' });
279
-
280
- const response = await client.fetch('https://juai8.com/zen7/v1/video/generate', {
281
- method: 'POST',
282
- headers: { 'Content-Type': 'application/json' },
283
- body: JSON.stringify({ prompt: 'a cat dancing' })
284
- });
285
-
286
- const result = await response.json();
287
- ```
288
-
289
- ### One-shot Request
290
-
291
- ```typescript
292
- import { x402Fetch } from 'moltspay';
293
-
294
- // Single paid request
295
- const response = await x402Fetch('https://juai8.com/zen7/v1/video/generate', {
296
- method: 'POST',
297
- body: JSON.stringify({ prompt: 'a cat dancing' })
298
- }, { chain: 'base' });
299
- ```
300
-
301
- ### How x402 Works (No Gas for Client)
302
-
303
- ```
304
- Client Agent Server Facilitator (Coinbase)
305
- โ”‚ โ”‚ โ”‚
306
- โ”‚ POST /x402pay โ”‚ โ”‚
307
- โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚ โ”‚
308
- โ”‚ โ”‚ โ”‚
309
- โ”‚ 402 + payment requirements โ”‚ โ”‚
310
- โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ โ”‚
311
- โ”‚ โ”‚ โ”‚
312
- โ”‚ [Sign EIP-3009] โ”‚ โ”‚
313
- โ”‚ (OFF-CHAIN, NO GAS!) โ”‚ โ”‚
314
- โ”‚ โ”‚ โ”‚
315
- โ”‚ POST + signature โ”‚ โ”‚
316
- โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚ Forward signature โ”‚
317
- โ”‚ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚
318
- โ”‚ โ”‚ โ”‚
319
- โ”‚ โ”‚ Execute transfer on-chain โ”‚
320
- โ”‚ โ”‚ (FACILITATOR PAYS GAS) โ”‚
321
- โ”‚ โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚
322
- โ”‚ โ”‚ โ”‚
323
- โ”‚ 200 OK + result โ”‚ โ”‚
324
- โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ โ”‚
325
- ```
326
-
327
- **Client agent requirements:**
328
- - โœ… Local wallet (just for signing)
329
- - โœ… USDC balance (owner sends once)
330
- - โŒ NO ETH/gas needed
331
- - โŒ NO API credentials needed
332
-
333
- ## Server Setup (Selling Services)
334
-
335
- To run a MoltsPay server that accepts x402 payments:
126
+ ## Server Setup (Mainnet)
336
127
 
337
- ### 1. Configure CDP Credentials (Required for Mainnet)
338
-
339
- ```bash
340
- # Copy the example config
341
- cp .env.example ~/.moltspay/.env
342
-
343
- # Edit with your CDP credentials (get from https://portal.cdp.coinbase.com/)
344
- nano ~/.moltspay/.env
345
- ```
128
+ **1. Get CDP credentials** from https://portal.cdp.coinbase.com/
346
129
 
130
+ **2. Create `~/.moltspay/.env`:**
347
131
  ```env
348
- # ~/.moltspay/.env
349
132
  USE_MAINNET=true
350
133
  CDP_API_KEY_ID=your-key-id
351
134
  CDP_API_KEY_SECRET=your-secret
352
135
  ```
353
136
 
354
- **Important:** Server does NOT need a private key! The x402 facilitator handles all on-chain settlement.
355
-
356
- ### 2. Create Services Manifest
357
-
358
- ```json
359
- {
360
- "provider": {
361
- "name": "My AI Service",
362
- "wallet": "0xYOUR_WALLET_ADDRESS",
363
- "chain": "base"
364
- },
365
- "services": [
366
- {
367
- "id": "my-service",
368
- "name": "My Service",
369
- "price": 0.99,
370
- "currency": "USDC",
371
- "command": "./handlers/my-service.sh",
372
- "input": { "prompt": { "type": "string", "required": true } },
373
- "output": { "result": { "type": "string" } }
374
- }
375
- ]
376
- }
377
- ```
378
-
379
- ### 3. Start Server
380
-
137
+ **3. Start server:**
381
138
  ```bash
382
- npx moltspay start ./moltspay.services.json --port 3000
139
+ npx moltspay start ./my-skill --port 3000
383
140
  ```
384
141
 
385
- The server will:
386
- - Return 402 with payment requirements for unpaid requests
387
- - Verify signatures with CDP facilitator
388
- - Execute service only after payment verification
389
- - Settle payment on-chain (facilitator pays gas)
142
+ Server does NOT need a private key - the x402 facilitator handles settlement.
390
143
 
391
- ## CDP Wallet Support (Optional, Advanced)
144
+ ## How x402 Works
392
145
 
393
- CDP wallet is an **optional alternative** for **client agents** who want Coinbase to host their wallet. Most users should use the simple local wallet above.
394
-
395
- ```bash
396
- # Only if you have CDP credentials and want hosted wallet
397
- export CDP_API_KEY_ID=your-key-id
398
- export CDP_API_KEY_SECRET=your-key-secret
399
- npx moltspay init --cdp --chain base
400
146
  ```
401
-
402
- ```typescript
403
- // Use CDP wallet
404
- const client = await createX402Client({ chain: 'base', useCDP: true });
147
+ Client Server CDP Facilitator
148
+ โ”‚ โ”‚ โ”‚
149
+ โ”‚ POST /execute โ”‚ โ”‚
150
+ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚ โ”‚
151
+ โ”‚ โ”‚ โ”‚
152
+ โ”‚ 402 + payment requirements โ”‚ โ”‚
153
+ โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ โ”‚
154
+ โ”‚ โ”‚ โ”‚
155
+ โ”‚ [Sign EIP-3009 - NO GAS] โ”‚ โ”‚
156
+ โ”‚ โ”‚ โ”‚
157
+ โ”‚ POST + X-Payment header โ”‚ โ”‚
158
+ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚ Verify signature โ”‚
159
+ โ”‚ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚
160
+ โ”‚ โ”‚ โ”‚
161
+ โ”‚ โ”‚ Execute transfer (pays gas) โ”‚
162
+ โ”‚ โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚
163
+ โ”‚ โ”‚ โ”‚
164
+ โ”‚ 200 OK + result โ”‚ โ”‚
165
+ โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ โ”‚
405
166
  ```
406
167
 
407
- ## API Reference
408
-
409
- ### PaymentAgent
168
+ **Client needs:** USDC balance only (no ETH/gas)
169
+ **Server needs:** CDP credentials only (no private key)
410
170
 
411
- ```typescript
412
- const agent = new PaymentAgent({
413
- chain: 'base', // Chain name
414
- walletAddress: '0x...', // Recipient address
415
- rpcUrl: '...', // Optional custom RPC
416
- });
171
+ ## CLI Reference
417
172
 
418
- // Create invoice
419
- const invoice = agent.createInvoice({
420
- orderId: 'order_123',
421
- amount: 2.0,
422
- service: 'video_generation',
423
- expiresMinutes: 30,
424
- });
173
+ ```bash
174
+ # === Client Commands ===
175
+ npx moltspay init # Create wallet
176
+ npx moltspay status # Check balance
177
+ npx moltspay config # Update limits
178
+ npx moltspay services <url> # List provider's services
179
+ npx moltspay pay <url> <service> # Pay and execute service
425
180
 
426
- // Verify payment
427
- const result = await agent.verifyPayment(txHash, {
428
- expectedAmount: 2.0,
429
- tolerance: 0.01, // 1% tolerance
430
- });
181
+ # === Server Commands ===
182
+ npx moltspay start <skill-dir> # Start server
183
+ npx moltspay stop # Stop server
184
+ npx moltspay validate <path> # Validate manifest
431
185
 
432
- // Get balance
433
- const balance = await agent.getBalance();
186
+ # === Options ===
187
+ --port <port> # Server port (default 3000)
188
+ --chain <chain> # Chain: base, polygon, ethereum
189
+ --max-per-tx <amount> # Spending limit per transaction
190
+ --max-per-day <amount> # Daily spending limit
434
191
  ```
435
192
 
436
- ### Wallet
193
+ ## Programmatic Usage
437
194
 
438
- ```typescript
439
- const wallet = new Wallet({
440
- chain: 'base',
441
- privateKey: '0x...',
442
- });
443
-
444
- // Get balance
445
- const balance = await wallet.getBalance();
446
-
447
- // Transfer USDC
448
- const result = await wallet.transfer('0x...', 10.0);
449
- ```
450
-
451
- ### SecureWallet
195
+ ### Client
452
196
 
453
197
  ```typescript
454
- const wallet = new SecureWallet({
455
- chain: 'base',
456
- limits: {
457
- singleMax: 100, // Max $100 per transfer
458
- dailyMax: 1000, // Max $1000 per day
459
- },
460
- whitelist: ['0x...'],
461
- });
198
+ import { MoltsPayClient } from 'moltspay/client';
462
199
 
463
- // Transfer with security checks
464
- const result = await wallet.transfer({
465
- to: '0x...',
466
- amount: 50,
467
- reason: 'Service payment',
468
- });
469
-
470
- // Approve pending transfer (when limit exceeded)
471
- await wallet.approve(requestId, 'admin');
472
-
473
- // Add to whitelist
474
- await wallet.addToWhitelist('0x...', 'admin');
475
- ```
476
-
477
- ### PermitPayment (EIP-2612)
200
+ const client = new MoltsPayClient({ chain: 'base' });
478
201
 
479
- ```typescript
480
- const permit = new PermitPayment({
481
- chain: 'base',
482
- privateKey: '0x...', // Service provider's key
202
+ // Pay for a service
203
+ const result = await client.execute('https://server.com', 'text-to-video', {
204
+ prompt: 'a cat dancing'
483
205
  });
484
206
 
485
- // Create permit request for user to sign
486
- const request = await permit.createPermitRequest(
487
- userAddress,
488
- amount,
489
- orderId
490
- );
491
-
492
- // After user signs, execute permit + transfer
493
- const result = await permit.executePermitAndTransfer(
494
- userAddress,
495
- amount,
496
- { v, r, s, deadline }
497
- );
207
+ console.log(result.video_url);
498
208
  ```
499
209
 
500
- ## CLI
501
-
502
- ```bash
503
- # Install globally
504
- npm install -g moltspay
505
-
506
- # === Client Commands ===
507
-
508
- # Initialize wallet (first time setup)
509
- npx moltspay init --chain base
510
-
511
- # Check wallet status and balance
512
- npx moltspay status
513
-
514
- # Update spending limits
515
- npx moltspay config # Interactive
516
- npx moltspay config --max-per-tx 50 --max-per-day 500 # Direct
517
-
518
- # Pay for a service
519
- npx moltspay pay http://server:3000 service-id --prompt "your prompt"
520
-
521
- # List services from a provider
522
- npx moltspay services http://server:3000
523
-
524
- # === Server Commands ===
210
+ ### Server
525
211
 
526
- # Start server from services manifest
527
- npx moltspay start ./moltspay.services.json --port 3000
528
-
529
- # Stop running server
530
- npx moltspay stop
531
-
532
- # === Legacy Commands ===
533
-
534
- # Generate invoice
535
- moltspay invoice --order order_123 --amount 2.0 --service video
212
+ ```typescript
213
+ import { MoltsPayServer } from 'moltspay/server';
536
214
 
537
- # Verify payment
538
- moltspay verify --tx 0x... --amount 2.0
215
+ const server = new MoltsPayServer('./moltspay.services.json');
539
216
 
540
- # Transfer USDC
541
- moltspay transfer --to 0x... --amount 10 --secure
217
+ // Register custom handler (optional - usually loaded from skill)
218
+ server.skill('text-to-video', async (params) => {
219
+ // implementation
220
+ return { video_url: '...' };
221
+ });
542
222
 
543
- # List supported chains
544
- moltspay chains
223
+ server.listen(3000);
545
224
  ```
546
225
 
547
- ### x402 CLI Examples (Cross-Platform)
548
-
549
- The x402 command sends JSON payloads. Quote handling differs by shell:
550
-
551
- **Linux / Mac (bash/zsh):**
552
- ```bash
553
- npx moltspay x402 https://example.com/api \
554
- -X POST \
555
- -d '{"prompt": "your text here"}' \
556
- -v
557
- ```
558
-
559
- **Windows PowerShell:**
560
- ```powershell
561
- # Option 1: Use a JSON file (recommended)
562
- echo '{"prompt": "your text here"}' > request.json
563
- npx moltspay x402 https://example.com/api -X POST -d "@request.json" -v
564
-
565
- # Option 2: Escape with backtick
566
- npx moltspay x402 https://example.com/api -X POST -d "{`"prompt`": `"your text`"}" -v
226
+ ## Supported Chains
567
227
 
568
- # Option 3: Use cmd /c wrapper
569
- cmd /c "npx moltspay x402 https://example.com/api -X POST -d ""{\""prompt\"": \""your text\""}"" -v"
570
- ```
228
+ | Chain | ID | Type |
229
+ |-------|-----|------|
230
+ | base | 8453 | Mainnet |
231
+ | polygon | 137 | Mainnet |
232
+ | ethereum | 1 | Mainnet |
233
+ | base_sepolia | 84532 | Testnet |
571
234
 
572
- **Windows CMD:**
573
- ```cmd
574
- npx moltspay x402 https://example.com/api -X POST -d "{\"prompt\": \"your text\"}" -v
575
- ```
235
+ ## Example: Zen7 Video Generation
576
236
 
577
- **Cross-platform tip:** For complex JSON, save to a file and use `-d @filename.json` - works on all systems!
237
+ Live service at `https://juai8.com/zen7/`
578
238
 
579
- ## Environment Variables
239
+ **Services:**
240
+ - `text-to-video` - $0.99 USDC
241
+ - `image-to-video` - $1.49 USDC
580
242
 
243
+ **Test it:**
581
244
  ```bash
582
- PAYMENT_AGENT_WALLET=0x... # Wallet address
583
- PAYMENT_AGENT_PRIVATE_KEY=0x... # Private key (for transfers)
245
+ npx moltspay services https://juai8.com/zen7
246
+ npx moltspay pay https://juai8.com/zen7 text-to-video --prompt "a happy cat"
584
247
  ```
585
248
 
586
- ## Supported Chains
587
-
588
- | Chain | Chain ID | Type | Status |
589
- |-------|----------|------|--------|
590
- | base | 8453 | Mainnet | โœ… |
591
- | polygon | 137 | Mainnet | โœ… |
592
- | ethereum | 1 | Mainnet | โœ… |
593
- | base_sepolia | 84532 | Testnet | โœ… |
594
- | sepolia | 11155111 | Testnet | โœ… |
595
-
596
- ## Security
249
+ ## Links
597
250
 
598
- - **Limits**: Single and daily transfer limits
599
- - **Whitelist**: Only transfer to approved addresses
600
- - **Audit Log**: Immutable, hash-chained logs
601
- - **Pending Approval**: Large transfers require manual approval
251
+ - **npm:** https://www.npmjs.com/package/moltspay
252
+ - **GitHub:** https://github.com/Yaqing2023/moltspay
253
+ - **x402 Protocol:** https://www.x402.org/
602
254
 
603
255
  ## License
604
256