x402-agent-pay 2.2.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/LICENSE +21 -0
- package/README.md +403 -0
- package/SKILL.md +125 -0
- package/dist/scripts/generate-pdf.d.ts +6 -0
- package/dist/scripts/generate-pdf.d.ts.map +1 -0
- package/dist/scripts/generate-pdf.js +179 -0
- package/dist/scripts/generate-pdf.js.map +1 -0
- package/dist/scripts/x402-fetch.d.ts +7 -0
- package/dist/scripts/x402-fetch.d.ts.map +1 -0
- package/dist/scripts/x402-fetch.js +162 -0
- package/dist/scripts/x402-fetch.js.map +1 -0
- package/dist/src/balance.d.ts +29 -0
- package/dist/src/balance.d.ts.map +1 -0
- package/dist/src/balance.js +94 -0
- package/dist/src/balance.js.map +1 -0
- package/dist/src/client.d.ts +90 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +235 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/config.d.ts +91 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +58 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/discovery.d.ts +98 -0
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +156 -0
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/facilitator.d.ts +30 -0
- package/dist/src/facilitator.d.ts.map +1 -0
- package/dist/src/facilitator.js +50 -0
- package/dist/src/facilitator.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +52 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp-server.d.ts +16 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +268 -0
- package/dist/src/mcp-server.js.map +1 -0
- package/dist/src/policy.d.ts +73 -0
- package/dist/src/policy.d.ts.map +1 -0
- package/dist/src/policy.js +271 -0
- package/dist/src/policy.js.map +1 -0
- package/dist/src/receipts.d.ts +52 -0
- package/dist/src/receipts.d.ts.map +1 -0
- package/dist/src/receipts.js +134 -0
- package/dist/src/receipts.js.map +1 -0
- package/mcp.json +41 -0
- package/package.json +65 -0
- package/registry.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ClawMD / Omnivalent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
# x402-agent-pay 💸
|
|
2
|
+
|
|
3
|
+
Seamless USDC payments for AI agents using the x402 protocol.
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://x402.org)
|
|
7
|
+
[](https://github.com/Omnivalent/x402-agent-pay/actions)
|
|
8
|
+
[](https://moltbook.com)
|
|
9
|
+
|
|
10
|
+
> Built on the official [@x402/fetch](https://github.com/coinbase/x402) SDK with spending controls and audit trails for autonomous agents.
|
|
11
|
+
|
|
12
|
+
## Demo
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
### Live Testnet Proof
|
|
17
|
+
|
|
18
|
+
✅ **Real USDC transaction on Base Sepolia:**
|
|
19
|
+
|
|
20
|
+
[View on Basescan →](https://sepolia.basescan.org/tx/0x51c7440999aebc9419ebb51a448e3f26f2f95d5e2f7b002b80c434e940d938a5)
|
|
21
|
+
|
|
22
|
+
- **Network:** Base Sepolia (Chain ID: 84532)
|
|
23
|
+
- **Token:** USDC (0x036CbD53842c5426634e7929541eC2318f3dCF7e)
|
|
24
|
+
- **TX Hash:** `0x51c7440999aebc9419ebb51a448e3f26f2f95d5e2f7b002b80c434e940d938a5`
|
|
25
|
+
|
|
26
|
+
## What It Does
|
|
27
|
+
|
|
28
|
+
When an AI agent hits a paid API (HTTP 402 Payment Required), this skill handles payment automatically — with safety guardrails:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
Agent → Paid API → 402 Response → Policy Check → Auto-Pay → Access Granted
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Before:** Agent hits 402, crashes or needs human intervention
|
|
35
|
+
**After:** Agent pays automatically within defined limits, continues working
|
|
36
|
+
|
|
37
|
+
## Why This Matters
|
|
38
|
+
|
|
39
|
+
Autonomous agents need to pay for things, but giving them unlimited wallet access is dangerous. This library adds:
|
|
40
|
+
|
|
41
|
+
- 🛡️ **Spending controls** — Per-transaction, daily, weekly, monthly limits
|
|
42
|
+
- ⚡ **Velocity limits** — Prevent rapid-fire loops from draining wallets
|
|
43
|
+
- 📋 **Whitelist/blacklist** — Control who can receive payments
|
|
44
|
+
- 📜 **Audit trail** — Every payment attempt logged with receipts
|
|
45
|
+
- 🔌 **Facilitator integration** — Connects to Coinbase's x402 facilitator
|
|
46
|
+
- ⚡ **Official SDK** — Built on Coinbase's @x402/fetch
|
|
47
|
+
- 🔍 **Service Discovery** — Find x402-enabled APIs programmatically (no hardcoding)
|
|
48
|
+
|
|
49
|
+
## How This Differs
|
|
50
|
+
|
|
51
|
+
There are dozens of x402 projects. Here's why this one matters:
|
|
52
|
+
|
|
53
|
+
| Feature | Raw @x402/fetch | x402-agent-pay |
|
|
54
|
+
|---------|-----------------|----------------|
|
|
55
|
+
| Auto-402 handling | ✅ | ✅ |
|
|
56
|
+
| Spending limits | ❌ | ✅ Per-tx, daily, weekly, monthly |
|
|
57
|
+
| Velocity limits | ❌ | ✅ Max tx/hour |
|
|
58
|
+
| Recipient controls | ❌ | ✅ Whitelist + blacklist |
|
|
59
|
+
| Receipt logging | ❌ | ✅ Full audit trail |
|
|
60
|
+
| OpenClaw integration | ❌ | ✅ Native skill |
|
|
61
|
+
| Policy enforcement | ❌ | ✅ Block before signing |
|
|
62
|
+
|
|
63
|
+
**The unique angle:** Purpose-built for autonomous OpenClaw agents with guardrails that prevent wallet drain from bugs, prompt injections, or infinite loops.
|
|
64
|
+
|
|
65
|
+
## Protocol Fee
|
|
66
|
+
|
|
67
|
+
x402-agent-pay includes an optional 0.5% protocol fee to support ongoing development.
|
|
68
|
+
|
|
69
|
+
| Property | Value |
|
|
70
|
+
|----------|-------|
|
|
71
|
+
| **Rate** | 0.5% (50 basis points) |
|
|
72
|
+
| **Recipient** | `0xe6Df117d19C7a5D08f20154BFa353caF1f9dB110` |
|
|
73
|
+
| **Minimum** | Fees under $0.001 skipped (gas savings) |
|
|
74
|
+
| **Code path** | `src/client.ts` → `transferProtocolFee()` |
|
|
75
|
+
|
|
76
|
+
**Full transparency:** The fee is a separate USDC transfer after each successful payment. You get full functionality with or without it.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// Disable fee (full functionality retained)
|
|
80
|
+
const client = new AgentPayClient({
|
|
81
|
+
privateKey: '0x...',
|
|
82
|
+
disableProtocolFee: true,
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Why it exists:** Sustainable open-source. If you find value, the fee supports maintenance. If not, disable it — no hard feelings.
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install x402-agent-pay
|
|
92
|
+
# or
|
|
93
|
+
git clone https://github.com/Omnivalent/x402-agent-pay
|
|
94
|
+
cd x402-agent-pay && npm install
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Quick Start
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { AgentPayClient } from 'x402-agent-pay';
|
|
101
|
+
|
|
102
|
+
const client = new AgentPayClient({
|
|
103
|
+
privateKey: process.env.WALLET_PRIVATE_KEY,
|
|
104
|
+
network: 'base',
|
|
105
|
+
policy: {
|
|
106
|
+
maxPerTransaction: 1.00, // Max $1 per request
|
|
107
|
+
dailyLimit: 10.00, // Max $10 per day
|
|
108
|
+
},
|
|
109
|
+
onPayment: (receipt) => {
|
|
110
|
+
console.log(`Paid ${receipt.amount} USDC to ${receipt.recipient}`);
|
|
111
|
+
},
|
|
112
|
+
onBlocked: (reason) => {
|
|
113
|
+
console.log(`Payment blocked: ${reason}`);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Auto-handles 402 with policy enforcement
|
|
118
|
+
const response = await client.fetch('https://paid-api.example.com/data');
|
|
119
|
+
const data = await response.json();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Spending Controls
|
|
123
|
+
|
|
124
|
+
| Policy | Default | Description |
|
|
125
|
+
|--------|---------|-------------|
|
|
126
|
+
| `maxPerTransaction` | $1.00 | Maximum per single payment |
|
|
127
|
+
| `dailyLimit` | $10.00 | Maximum total per 24 hours |
|
|
128
|
+
| `weeklyLimit` | none | Maximum per week (optional) |
|
|
129
|
+
| `monthlyLimit` | none | Maximum per month (optional) |
|
|
130
|
+
| `maxTransactionsPerHour` | 60 | Velocity limit — prevents loops |
|
|
131
|
+
| `perRecipientDailyLimit` | none | Max to any single address per day |
|
|
132
|
+
| `approvedRecipients` | none | Whitelist of allowed addresses |
|
|
133
|
+
| `blockedRecipients` | none | Blacklist of blocked addresses |
|
|
134
|
+
| `autoApproveUnder` | $0.10 | Skip detailed logging for tiny amounts |
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const client = new AgentPayClient({
|
|
138
|
+
privateKey: process.env.WALLET_PRIVATE_KEY,
|
|
139
|
+
policy: {
|
|
140
|
+
maxPerTransaction: 5.00,
|
|
141
|
+
dailyLimit: 50.00,
|
|
142
|
+
weeklyLimit: 200.00,
|
|
143
|
+
monthlyLimit: 500.00,
|
|
144
|
+
maxTransactionsPerHour: 30, // Prevent rapid loops
|
|
145
|
+
perRecipientDailyLimit: 10.00, // Max $10 to any one address
|
|
146
|
+
approvedRecipients: ['0x1234...'], // Only these can receive
|
|
147
|
+
blockedRecipients: ['0xScam...'], // Never pay these
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Service Discovery
|
|
153
|
+
|
|
154
|
+
Find x402-enabled APIs without hardcoding URLs — a first for agent payment infrastructure:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { discoverServices, ServiceDiscovery } from 'x402-agent-pay';
|
|
158
|
+
|
|
159
|
+
// Find all weather APIs
|
|
160
|
+
const weatherApis = await discoverServices({ category: 'weather' });
|
|
161
|
+
|
|
162
|
+
// Find cheap services under $0.01
|
|
163
|
+
const cheapServices = await discoverServices({ maxPrice: 0.01 });
|
|
164
|
+
|
|
165
|
+
// Find services on Base network
|
|
166
|
+
const baseServices = await discoverServices({ network: 'eip155:8453' });
|
|
167
|
+
|
|
168
|
+
// Search by keyword
|
|
169
|
+
const aiServices = await discoverServices({ query: 'trading' });
|
|
170
|
+
|
|
171
|
+
// Get the cheapest option in a category
|
|
172
|
+
const discovery = new ServiceDiscovery();
|
|
173
|
+
const cheapestWeather = await discovery.findCheapest('weather');
|
|
174
|
+
console.log(cheapestWeather?.url); // → Use with client.fetch()
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Available Categories:** `weather`, `data`, `ai`, `compute`, `storage`, `oracle`, `search`, `media`, `finance`
|
|
178
|
+
|
|
179
|
+
The registry is open — submit your x402-enabled service via PR to `registry.json`.
|
|
180
|
+
|
|
181
|
+
## MCP Server (Claude/GPT Integration)
|
|
182
|
+
|
|
183
|
+
x402-agent-pay includes an MCP server for direct integration with Claude, GPT, and other LLM agents:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Run the MCP server
|
|
187
|
+
X402_WALLET_KEY=0x... npm run mcp
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**MCP Tools:**
|
|
191
|
+
| Tool | Description |
|
|
192
|
+
|------|-------------|
|
|
193
|
+
| `x402_pay` | Make a paid request to an x402 endpoint |
|
|
194
|
+
| `x402_discover` | Find services by category/price/network |
|
|
195
|
+
| `x402_balance` | Check USDC balance |
|
|
196
|
+
| `x402_status` | Get spending limits and usage |
|
|
197
|
+
| `x402_history` | Get payment receipts |
|
|
198
|
+
|
|
199
|
+
**Claude Desktop config** (`~/.config/claude/mcp.json`):
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"mcpServers": {
|
|
203
|
+
"x402": {
|
|
204
|
+
"command": "npx",
|
|
205
|
+
"args": ["x402-agent-pay"],
|
|
206
|
+
"env": {
|
|
207
|
+
"X402_WALLET_KEY": "0x..."
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## CLI Usage
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Set your wallet key
|
|
218
|
+
export WALLET_PRIVATE_KEY=0x...
|
|
219
|
+
|
|
220
|
+
# Make a paid request
|
|
221
|
+
npx ts-node scripts/x402-fetch.ts https://paid-api.example.com/data
|
|
222
|
+
|
|
223
|
+
# Check balance
|
|
224
|
+
npx ts-node scripts/x402-fetch.ts balance 0xYourWallet --network base
|
|
225
|
+
|
|
226
|
+
# View spending status
|
|
227
|
+
npx ts-node scripts/x402-fetch.ts status
|
|
228
|
+
|
|
229
|
+
# View payment history
|
|
230
|
+
npx ts-node scripts/x402-fetch.ts history 10
|
|
231
|
+
|
|
232
|
+
# Custom limits
|
|
233
|
+
npx ts-node scripts/x402-fetch.ts https://api.example.com --max-per-tx 5 --daily-limit 50
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Supported Networks
|
|
237
|
+
|
|
238
|
+
| Network | Chain ID | Status |
|
|
239
|
+
|---------|----------|--------|
|
|
240
|
+
| Base | 8453 | ✅ Primary |
|
|
241
|
+
| Ethereum | 1 | ✅ Supported |
|
|
242
|
+
| Arbitrum | 42161 | ✅ Supported |
|
|
243
|
+
| Optimism | 10 | ✅ Supported |
|
|
244
|
+
| Polygon | 137 | ✅ Supported |
|
|
245
|
+
| Base Sepolia | 84532 | ✅ Testnet |
|
|
246
|
+
|
|
247
|
+
## API Reference
|
|
248
|
+
|
|
249
|
+
### AgentPayClient
|
|
250
|
+
|
|
251
|
+
Main client with policy enforcement and receipt tracking.
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
const client = new AgentPayClient(config: AgentPayConfig);
|
|
255
|
+
|
|
256
|
+
// Make payment-enabled request
|
|
257
|
+
await client.fetch(url, init?, options?);
|
|
258
|
+
|
|
259
|
+
// Get spending status
|
|
260
|
+
client.getSpendingStatus();
|
|
261
|
+
|
|
262
|
+
// Get payment history
|
|
263
|
+
client.getHistory(limit?);
|
|
264
|
+
|
|
265
|
+
// Export receipts
|
|
266
|
+
client.exportReceiptsCsv();
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Simple Fetch (No Policy)
|
|
270
|
+
|
|
271
|
+
For cases where you want direct SDK access without policy enforcement:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import { createSimpleFetch } from 'x402-agent-pay';
|
|
275
|
+
|
|
276
|
+
const fetch402 = createSimpleFetch(process.env.WALLET_PRIVATE_KEY);
|
|
277
|
+
const response = await fetch402('https://paid-api.com/data');
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Balance Checking
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { checkBalance, checkAllBalances } from 'x402-agent-pay';
|
|
284
|
+
|
|
285
|
+
// Single network
|
|
286
|
+
const balance = await checkBalance('0xYourWallet', 'base');
|
|
287
|
+
console.log(`${balance.balanceUsdc} USDC`);
|
|
288
|
+
|
|
289
|
+
// All networks
|
|
290
|
+
const balances = await checkAllBalances('0xYourWallet');
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Receipt Storage
|
|
294
|
+
|
|
295
|
+
All payment attempts are logged to `receipts.json`:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
300
|
+
"timestamp": "2026-02-09T07:30:00.000Z",
|
|
301
|
+
"url": "https://api.example.com/data",
|
|
302
|
+
"amount": "0.500000",
|
|
303
|
+
"currency": "USDC",
|
|
304
|
+
"network": "base",
|
|
305
|
+
"recipient": "0x1234...",
|
|
306
|
+
"txHash": "0xabc123...",
|
|
307
|
+
"status": "success"
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## How x402 Works
|
|
312
|
+
|
|
313
|
+
1. **Request** → Client calls a paid API
|
|
314
|
+
2. **402 Response** → Server returns payment requirements in header
|
|
315
|
+
3. **Policy Check** → Client validates against spending limits
|
|
316
|
+
4. **Sign & Pay** → Client signs EIP-712 payment via facilitator
|
|
317
|
+
5. **Retry** → Request retried with payment proof header
|
|
318
|
+
6. **Access** → Server verifies, returns resource
|
|
319
|
+
7. **Receipt** → Payment logged for audit
|
|
320
|
+
|
|
321
|
+
## Security
|
|
322
|
+
|
|
323
|
+
**Built-in protections:**
|
|
324
|
+
- ✅ Built on official Coinbase @x402/fetch SDK
|
|
325
|
+
- ✅ Private keys never logged or transmitted
|
|
326
|
+
- ✅ Policy enforcement before every payment
|
|
327
|
+
- ✅ Full audit trail in receipts.json
|
|
328
|
+
- ✅ EIP-712 typed data signatures
|
|
329
|
+
|
|
330
|
+
**Recommended practices:**
|
|
331
|
+
|
|
332
|
+
| Risk | Mitigation |
|
|
333
|
+
|------|------------|
|
|
334
|
+
| **Wallet drain** | Use a hot wallet with small balance (~$50). Never use your main wallet. |
|
|
335
|
+
| **Infinite loops** | Set `maxTransactionsPerHour: 30` to cap velocity |
|
|
336
|
+
| **Prompt injection** | Policy enforcement happens in code, not LLM — can't be bypassed by prompts |
|
|
337
|
+
| **Malicious 402 endpoints** | Use `approvedRecipients` whitelist for production |
|
|
338
|
+
| **Key exposure** | Use env vars, never hardcode. Consider [Circle Programmable Wallets](https://developers.circle.com/w3s/programmable-wallets-quickstart) for production. |
|
|
339
|
+
|
|
340
|
+
**Default policy is conservative:**
|
|
341
|
+
```typescript
|
|
342
|
+
{
|
|
343
|
+
maxPerTransaction: 1.00, // Max $1 per tx
|
|
344
|
+
dailyLimit: 10.00, // Max $10/day
|
|
345
|
+
maxTransactionsPerHour: 60, // Velocity limit
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Quick Demo
|
|
350
|
+
|
|
351
|
+
One-command proof that it works:
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
# Clone and install
|
|
355
|
+
git clone https://github.com/Omnivalent/x402-agent-pay
|
|
356
|
+
cd x402-agent-pay && npm install
|
|
357
|
+
|
|
358
|
+
# Set wallet key (get testnet USDC from faucet.circle.com)
|
|
359
|
+
export WALLET_PRIVATE_KEY=0x...
|
|
360
|
+
|
|
361
|
+
# Check balance
|
|
362
|
+
npm run x402 balance 0xYourWallet --network baseSepolia
|
|
363
|
+
|
|
364
|
+
# Make a test payment (uses demo endpoint)
|
|
365
|
+
npm run x402 https://weather.x402.org/current?city=berlin --network baseSepolia
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**Expected flow:**
|
|
369
|
+
```
|
|
370
|
+
→ GET /current?city=berlin
|
|
371
|
+
← 402 Payment Required (0.001 USDC)
|
|
372
|
+
→ Policy check: ✓ under $1 limit
|
|
373
|
+
→ Sign EIP-712 payment
|
|
374
|
+
← 200 OK + weather data
|
|
375
|
+
→ Receipt saved to receipts.json
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## For OpenClaw Agents
|
|
379
|
+
|
|
380
|
+
See [SKILL.md](./SKILL.md) for OpenClaw integration.
|
|
381
|
+
|
|
382
|
+
```
|
|
383
|
+
~/.openclaw/workspace/skills/x402/
|
|
384
|
+
├── SKILL.md # Skill manifest
|
|
385
|
+
├── src/ # Source code
|
|
386
|
+
├── scripts/ # CLI tools
|
|
387
|
+
└── receipts.json # Payment history
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Links
|
|
391
|
+
|
|
392
|
+
- [x402 Protocol](https://x402.org)
|
|
393
|
+
- [x402 SDK (Coinbase)](https://github.com/coinbase/x402)
|
|
394
|
+
- [OpenClaw](https://github.com/openclaw/openclaw)
|
|
395
|
+
- [ClawHub](https://clawhub.com)
|
|
396
|
+
|
|
397
|
+
## License
|
|
398
|
+
|
|
399
|
+
MIT
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
Built by [ClawMD](https://moltbook.com/u/ClawMD) 🩺 for the USDC Hackathon 2026
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: x402-agent-pay
|
|
3
|
+
description: Seamless USDC payments for AI agents with spending controls. Auto-handles HTTP 402 Payment Required responses using the x402 protocol. Built on official @x402/fetch SDK.
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
author: ClawMD
|
|
6
|
+
repository: https://github.com/Omnivalent/x402-agent-pay
|
|
7
|
+
metadata:
|
|
8
|
+
openclaw:
|
|
9
|
+
emoji: 💸
|
|
10
|
+
requires:
|
|
11
|
+
node: ">=18"
|
|
12
|
+
env:
|
|
13
|
+
- WALLET_PRIVATE_KEY
|
|
14
|
+
capabilities:
|
|
15
|
+
- payments
|
|
16
|
+
- wallet
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# x402-agent-pay
|
|
20
|
+
|
|
21
|
+
Pay for APIs automatically when you hit a 402 Payment Required response.
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { AgentPayClient } from 'x402-agent-pay';
|
|
27
|
+
|
|
28
|
+
const client = new AgentPayClient({
|
|
29
|
+
privateKey: process.env.WALLET_PRIVATE_KEY,
|
|
30
|
+
network: 'base',
|
|
31
|
+
policy: {
|
|
32
|
+
maxPerTransaction: 1.00, // Max $1 per request
|
|
33
|
+
dailyLimit: 10.00, // Max $10 per day
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// This auto-pays if the API requires payment
|
|
38
|
+
const response = await client.fetch('https://paid-api.example.com/data');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
### ~pay <url>
|
|
44
|
+
Make a payment-enabled request to a URL.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
~pay https://api.example.com/paid-endpoint
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### ~balance [network]
|
|
51
|
+
Check your USDC balance.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
~balance base
|
|
55
|
+
~balance ethereum
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### ~spending
|
|
59
|
+
Show current spending status vs limits.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
~spending
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### ~history [limit]
|
|
66
|
+
Show recent payment history.
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
~history 10
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Spending Controls
|
|
73
|
+
|
|
74
|
+
The agent enforces spending policies to prevent runaway costs:
|
|
75
|
+
|
|
76
|
+
| Control | Default | Description |
|
|
77
|
+
|---------|---------|-------------|
|
|
78
|
+
| `maxPerTransaction` | $1.00 | Maximum per single payment |
|
|
79
|
+
| `dailyLimit` | $10.00 | Maximum total per 24 hours |
|
|
80
|
+
| `approvedRecipients` | none | Whitelist of allowed addresses |
|
|
81
|
+
| `blockedRecipients` | none | Blacklist of blocked addresses |
|
|
82
|
+
| `autoApproveUnder` | $0.10 | Skip logging for tiny amounts |
|
|
83
|
+
|
|
84
|
+
## Payment Flow
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
1. Agent calls paid API
|
|
88
|
+
2. API returns HTTP 402 with payment requirements
|
|
89
|
+
3. x402-agent-pay checks spending policy
|
|
90
|
+
4. If allowed: signs payment, retries request with payment header
|
|
91
|
+
5. If blocked: throws PaymentBlockedError
|
|
92
|
+
6. Receipt stored for audit trail
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Supported Networks
|
|
96
|
+
|
|
97
|
+
- **Base** (primary) - Chain ID 8453
|
|
98
|
+
- **Ethereum** - Chain ID 1
|
|
99
|
+
- **Arbitrum** - Chain ID 42161
|
|
100
|
+
- **Optimism** - Chain ID 10
|
|
101
|
+
- **Polygon** - Chain ID 137
|
|
102
|
+
- **Base Sepolia** (testnet) - Chain ID 84532
|
|
103
|
+
|
|
104
|
+
## Environment Variables
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Required
|
|
108
|
+
WALLET_PRIVATE_KEY=0x...
|
|
109
|
+
|
|
110
|
+
# Optional RPC overrides
|
|
111
|
+
BASE_RPC_URL=https://mainnet.base.org
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Security
|
|
115
|
+
|
|
116
|
+
- Private keys never logged or transmitted
|
|
117
|
+
- Policy enforcement before every payment
|
|
118
|
+
- Full audit trail in receipts.json
|
|
119
|
+
- Built on official Coinbase @x402/fetch SDK
|
|
120
|
+
|
|
121
|
+
## Links
|
|
122
|
+
|
|
123
|
+
- [x402 Protocol](https://x402.org)
|
|
124
|
+
- [Coinbase x402 SDK](https://github.com/coinbase/x402)
|
|
125
|
+
- [OpenClaw](https://github.com/openclaw/openclaw)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-pdf.d.ts","sourceRoot":"","sources":["../../scripts/generate-pdf.ts"],"names":[],"mappings":";AACA;;GAEG"}
|