agentwallet-sdk 1.0.0 → 2.0.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.
Files changed (2) hide show
  1. package/README.md +92 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -178,6 +178,98 @@ for (const entry of history) {
178
178
  | **Arbitrum** | ✅ | DeFi agents |
179
179
  | **Polygon** | ✅ | Micropayments |
180
180
 
181
+ ## x402 Protocol Support
182
+
183
+ Agent Wallet natively supports the [x402 protocol](https://x402.org) — the open standard for HTTP 402 machine payments. Your agent can automatically pay any x402-enabled API (Stripe, Coinbase, etc.) using USDC on Base, while respecting on-chain spend limits.
184
+
185
+ ### Quick Start
186
+
187
+ ```typescript
188
+ import { createWallet, createX402Client } from 'agentwallet-sdk';
189
+
190
+ // 1. Create your wallet
191
+ const wallet = createWallet({ accountAddress, chain: 'base', walletClient });
192
+
193
+ // 2. Create an x402-aware client
194
+ const client = createX402Client(wallet, {
195
+ globalDailyLimit: 50_000_000n, // 50 USDC/day
196
+ globalPerRequestMax: 5_000_000n, // 5 USDC max per request
197
+ serviceBudgets: [
198
+ { service: 'api.weather.com', maxPerRequest: 1_000_000n, dailyLimit: 10_000_000n },
199
+ ],
200
+ });
201
+
202
+ // 3. Use it like fetch — 402 responses are handled automatically
203
+ const response = await client.fetch('https://api.weather.com/forecast');
204
+ const data = await response.json();
205
+ // If the API returned 402, the client:
206
+ // - Parsed payment requirements from the PAYMENT-REQUIRED header
207
+ // - Checked your budget (client-side + on-chain)
208
+ // - Paid USDC via your AgentWallet contract
209
+ // - Retried the request with payment proof
210
+ ```
211
+
212
+ ### Drop-in Fetch Replacement
213
+
214
+ ```typescript
215
+ import { createX402Fetch } from 'agentwallet-sdk';
216
+
217
+ const x402Fetch = createX402Fetch(wallet, { globalDailyLimit: 100_000_000n });
218
+
219
+ // Use exactly like fetch()
220
+ const res = await x402Fetch('https://any-x402-api.com/endpoint');
221
+ ```
222
+
223
+ ### Budget Controls
224
+
225
+ ```typescript
226
+ // Check spending
227
+ const summary = client.getDailySpendSummary();
228
+ console.log(`Today's spend: ${summary.global} (resets at ${summary.resetsAt})`);
229
+
230
+ // View transaction log
231
+ const logs = client.getTransactionLog({ service: 'api.weather.com' });
232
+
233
+ // Add budget at runtime
234
+ client.budgetTracker.setServiceBudget({
235
+ service: 'new-api.com',
236
+ maxPerRequest: 2_000_000n,
237
+ dailyLimit: 20_000_000n,
238
+ });
239
+ ```
240
+
241
+ ### Payment Approval Callback
242
+
243
+ ```typescript
244
+ const client = createX402Client(wallet, {
245
+ onBeforePayment: async (req, url) => {
246
+ console.log(`About to pay ${req.amount} to ${req.payTo} for ${url}`);
247
+ return true; // return false to reject
248
+ },
249
+ onPaymentComplete: (log) => {
250
+ console.log(`Paid ${log.amount} via tx ${log.txHash}`);
251
+ },
252
+ });
253
+ ```
254
+
255
+ ### How x402 Works
256
+
257
+ ```
258
+ Agent → GET /api/data → Server returns 402 + PAYMENT-REQUIRED header
259
+
260
+ Client parses payment requirements (amount, token, recipient, network)
261
+
262
+ Budget check (client-side caps + on-chain spend limits)
263
+
264
+ AgentWallet executes USDC transfer on Base
265
+
266
+ Client retries request with X-PAYMENT header (payment proof)
267
+
268
+ Server verifies payment → returns 200 + data
269
+ ```
270
+
271
+ Your agent's keys never leave the non-custodial wallet. All payments respect on-chain spend limits set by the wallet owner.
272
+
181
273
  ## How It Works
182
274
 
183
275
  1. **Deploy** an AgentAccountV2 (ERC-6551 token-bound account tied to an NFT)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentwallet-sdk",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript SDK for Agent Wallet — autonomous crypto spending for AI agents with user-set limits",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",