moltspay 0.8.14 โ 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 +156 -504
- package/dist/cli/index.js +553 -171
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +555 -173
- package/dist/cli/index.mjs.map +1 -1
- package/dist/facilitators/index.d.mts +61 -0
- package/dist/facilitators/index.d.ts +61 -0
- package/dist/facilitators/index.js +502 -0
- package/dist/facilitators/index.js.map +1 -0
- package/dist/facilitators/index.mjs +461 -0
- package/dist/facilitators/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +583 -190
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +580 -192
- package/dist/index.mjs.map +1 -1
- package/dist/registry-OsEO2dOu.d.mts +233 -0
- package/dist/registry-OsEO2dOu.d.ts +233 -0
- package/dist/server/index.d.mts +19 -15
- package/dist/server/index.d.ts +19 -15
- package/dist/server/index.js +514 -145
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +514 -145
- package/dist/server/index.mjs.map +1 -1
- package/package.json +7 -2
- package/schemas/moltspay.services.schema.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
# MoltsPay
|
|
2
2
|
|
|
3
|
-
Blockchain payment infrastructure for AI Agents
|
|
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
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
55
|
+
That's it! Your skill now accepts x402 payments.
|
|
86
56
|
|
|
87
|
-
|
|
57
|
+
### For Clients (Buying)
|
|
88
58
|
|
|
89
|
-
**
|
|
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
|
-
**
|
|
104
|
-
|
|
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
|
-
**
|
|
68
|
+
**3. Use paid services:**
|
|
109
69
|
```bash
|
|
110
|
-
npx moltspay
|
|
70
|
+
npx moltspay pay https://server.com text-to-video --prompt "a cat dancing"
|
|
111
71
|
```
|
|
112
72
|
|
|
113
|
-
|
|
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
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
84
|
+
**Entry point discovery:**
|
|
85
|
+
1. If `package.json` exists โ uses `main` field
|
|
86
|
+
2. Otherwise โ defaults to `index.js`
|
|
165
87
|
|
|
166
|
-
|
|
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
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
111
|
+
"output": {
|
|
112
|
+
"result_url": { "type": "string" }
|
|
113
|
+
}
|
|
114
|
+
}]
|
|
218
115
|
}
|
|
219
116
|
```
|
|
220
117
|
|
|
221
|
-
###
|
|
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
|
-
|
|
270
|
-
#
|
|
271
|
-
|
|
121
|
+
npx moltspay validate ./my-skill
|
|
122
|
+
# or
|
|
123
|
+
npx moltspay validate ./moltspay.services.json
|
|
272
124
|
```
|
|
273
125
|
|
|
274
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
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 ./
|
|
139
|
+
npx moltspay start ./my-skill --port 3000
|
|
383
140
|
```
|
|
384
141
|
|
|
385
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
### PaymentAgent
|
|
168
|
+
**Client needs:** USDC balance only (no ETH/gas)
|
|
169
|
+
**Server needs:** CDP credentials only (no private key)
|
|
410
170
|
|
|
411
|
-
|
|
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
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
433
|
-
|
|
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
|
-
|
|
193
|
+
## Programmatic Usage
|
|
437
194
|
|
|
438
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
480
|
-
const
|
|
481
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
527
|
-
|
|
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
|
-
|
|
538
|
-
moltspay verify --tx 0x... --amount 2.0
|
|
215
|
+
const server = new MoltsPayServer('./moltspay.services.json');
|
|
539
216
|
|
|
540
|
-
|
|
541
|
-
|
|
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
|
-
|
|
544
|
-
moltspay chains
|
|
223
|
+
server.listen(3000);
|
|
545
224
|
```
|
|
546
225
|
|
|
547
|
-
|
|
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
|
-
|
|
569
|
-
|
|
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
|
-
|
|
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
|
-
|
|
237
|
+
Live service at `https://juai8.com/zen7/`
|
|
578
238
|
|
|
579
|
-
|
|
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
|
-
|
|
583
|
-
|
|
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
|
-
##
|
|
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
|
-
- **
|
|
599
|
-
- **
|
|
600
|
-
- **
|
|
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
|
|