{"_id":"@agentokratia/x402-escrow","_rev":"5-2137ccd70740d05515046ae83873ccec","name":"@agentokratia/x402-escrow","dist-tags":{"latest":"2.1.2"},"versions":{"2.0.0":{"name":"@agentokratia/x402-escrow","version":"2.0.0","keywords":["x402","escrow","payments","ethereum","base","usdc","erc-3009","session"],"author":{"name":"Agentokratia"},"license":"MIT","_id":"@agentokratia/x402-escrow@2.0.0","maintainers":[{"name":"panche","email":"panche@agentokratia.com"}],"homepage":"https://github.com/agentokratia/x402-escrow/tree/main/packages/escrow","bugs":{"url":"https://github.com/agentokratia/x402-escrow/issues"},"dist":{"shasum":"d8dd1a210cee9687c7f23090e1202944dc52e444","tarball":"https://registry.npmjs.org/@agentokratia/x402-escrow/-/x402-escrow-2.0.0.tgz","fileCount":23,"integrity":"sha512-YMbajiBEZ9aDkWjU2BRJ/uoan5AUD82wcfW2Hc8vUKJGAFMM00bX+WONdNDhfnFiBKTHDWo32C4cZ5p1KM6YAA==","signatures":[{"sig":"MEQCIC7KldxpRrHLrhcMlcG0BNnW8Tyhn6rfbb8RxA6riNk+AiACUA24es1JcJHwEFTxbw5+kwtm1pEekk0J7l/5tgjpaA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":336507},"main":"./dist/index.cjs","type":"module","_from":"file:agentokratia-x402-escrow-2.0.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js","require":"./dist/client/index.cjs"},"./server":{"types":"./dist/server/index.d.ts","import":"./dist/server/index.js","require":"./dist/server/index.cjs"}},"scripts":{"dev":"tsup --watch","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"panche","email":"panche@agentokratia.com"},"_resolved":"/tmp/09d4dc8f6d0d1ea15aca7c27427e5088/agentokratia-x402-escrow-2.0.0.tgz","_integrity":"sha512-YMbajiBEZ9aDkWjU2BRJ/uoan5AUD82wcfW2Hc8vUKJGAFMM00bX+WONdNDhfnFiBKTHDWo32C4cZ5p1KM6YAA==","repository":{"url":"git+https://github.com/agentokratia/x402-escrow.git","type":"git","directory":"packages/escrow"},"_npmVersion":"10.8.2","description":"Escrow payment scheme for x402 protocol - session-based payments for high-frequency APIs","directories":{},"_nodeVersion":"20.19.6","dependencies":{"viem":"^2.21.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","@x402/core":"^2.0.0","typescript":"^5.0.0","@x402/fetch":"^2.0.0"},"peerDependencies":{"@x402/core":"^2.0.0","@x402/fetch":"^2.0.0"},"peerDependenciesMeta":{"@x402/fetch":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/x402-escrow_2.0.0_1766770998759_0.8911441623647658","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@agentokratia/x402-escrow","version":"2.0.1","keywords":["x402","escrow","payments","ethereum","base","usdc","erc-3009","session"],"author":{"name":"Agentokratia"},"license":"MIT","_id":"@agentokratia/x402-escrow@2.0.1","maintainers":[{"name":"panche","email":"panche@agentokratia.com"}],"homepage":"https://github.com/Agentokratia/x402-escrow/tree/main/packages/escrow","bugs":{"url":"https://github.com/Agentokratia/x402-escrow/issues"},"dist":{"shasum":"9af6f00f273c70e29ec6829e7d9d8bd7d2971fa6","tarball":"https://registry.npmjs.org/@agentokratia/x402-escrow/-/x402-escrow-2.0.1.tgz","fileCount":23,"integrity":"sha512-3VPJQFZi03spiOPKbbISnuREmuKmMHUT0d47T5QMu5kjhzYSS5sUhepmCt0dz539aTOYFZJyfgQmSJlO/ydhAw==","signatures":[{"sig":"MEYCIQC+5U9RaZAk9krMG4cFIYrDRXhp3lE+lr0VFxVaJsI/gAIhAL8TClUvNPVAiIhNC9hz32pDZWH7xAH71zmJ7bAv5D/b","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agentokratia%2fx402-escrow@2.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":377050},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js","require":"./dist/client/index.cjs"},"./server":{"types":"./dist/server/index.d.ts","import":"./dist/server/index.js","require":"./dist/server/index.cjs"}},"gitHead":"187171afcfa96a976f09be5ecc5be6fa4292229e","scripts":{"dev":"tsup --watch","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:7e60eefe-f360-42eb-af3e-74f190baf245"}},"repository":{"url":"git+https://github.com/Agentokratia/x402-escrow.git","type":"git","directory":"packages/escrow"},"_npmVersion":"11.7.0","description":"Escrow payment scheme for x402 protocol - session-based payments for high-frequency APIs","directories":{},"_nodeVersion":"22.21.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","viem":"^2.21.9","@x402/core":"^2.0.0","typescript":"^5.0.0","@x402/fetch":"^2.0.0"},"peerDependencies":{"viem":"^2.21.9","@x402/core":"^2.0.0","@x402/fetch":"^2.0.0"},"peerDependenciesMeta":{"@x402/fetch":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/x402-escrow_2.0.1_1766958674226_0.7343758628056347","host":"s3://npm-registry-packages-npm-production"}},"2.1.0":{"name":"@agentokratia/x402-escrow","version":"2.1.0","keywords":["x402","escrow","payments","ethereum","base","usdc","erc-3009","session"],"author":{"name":"Agentokratia"},"license":"MIT","_id":"@agentokratia/x402-escrow@2.1.0","maintainers":[{"name":"panche","email":"panche@agentokratia.com"}],"homepage":"https://github.com/Agentokratia/x402-escrow/tree/main/packages/escrow","bugs":{"url":"https://github.com/Agentokratia/x402-escrow/issues"},"dist":{"shasum":"b42ceb863fa18be8bc476c96bf999cd18241deae","tarball":"https://registry.npmjs.org/@agentokratia/x402-escrow/-/x402-escrow-2.1.0.tgz","fileCount":25,"integrity":"sha512-TnubyWzzAQ6wAVLtp5bs+b4YxHLkxBFfCkpfFKejeFpDxXs4UEcLqqAxym4sS+8nXkvE2GlFCYARebw0bH5VBA==","signatures":[{"sig":"MEYCIQCgrFOB2kDeQ7ekTV92wlHJY5RgaNU/6UGNkRgHAdvSlAIhAL7uVXefaC/q71ofofiqWUwfSQh1pZDNW+7Uan+lcGFY","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agentokratia%2fx402-escrow@2.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":529483},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js","require":"./dist/client/index.cjs"},"./server":{"types":"./dist/server/index.d.ts","import":"./dist/server/index.js","require":"./dist/server/index.cjs"}},"gitHead":"a9c13aa7a53fb735a8d8db6610d00598ee0d63f5","scripts":{"dev":"tsup --watch","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:7e60eefe-f360-42eb-af3e-74f190baf245"}},"repository":{"url":"git+https://github.com/Agentokratia/x402-escrow.git","type":"git","directory":"packages/escrow"},"_npmVersion":"11.9.0","description":"Escrow payment scheme for x402 protocol - session-based payments for high-frequency APIs","directories":{},"_nodeVersion":"22.22.0","dependencies":{"pako":"^2.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","viem":"^2.21.9","@x402/core":"^2.0.0","typescript":"^5.0.0","@types/pako":"^2.0.4","@x402/fetch":"^2.0.0"},"peerDependencies":{"viem":"^2.21.9","@x402/core":"^2.0.0","@x402/fetch":"^2.0.0"},"peerDependenciesMeta":{"@x402/fetch":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/x402-escrow_2.1.0_1770397838967_0.870373870428375","host":"s3://npm-registry-packages-npm-production"}},"2.1.1":{"name":"@agentokratia/x402-escrow","version":"2.1.1","keywords":["x402","escrow","payments","ethereum","base","usdc","erc-3009","session"],"author":{"name":"Agentokratia"},"license":"MIT","_id":"@agentokratia/x402-escrow@2.1.1","maintainers":[{"name":"panche","email":"panche@agentokratia.com"}],"homepage":"https://github.com/Agentokratia/x402-escrow/tree/main/packages/escrow","bugs":{"url":"https://github.com/Agentokratia/x402-escrow/issues"},"dist":{"shasum":"98c3eeee96423050b03ae783e9ce466463317a95","tarball":"https://registry.npmjs.org/@agentokratia/x402-escrow/-/x402-escrow-2.1.1.tgz","fileCount":25,"integrity":"sha512-DWIEIQ+kNoxtqXSROCkWfTOopFL0GIYtAE+lP12wRiINjxOBqIa6kdGIYZZtj54JevnyyXQcq90Qp+UyGi2k7A==","signatures":[{"sig":"MEUCICwiqifw7ZYzhvkDouTteDBfifGxDUQ+mFVigO+WFVkQAiEA2KXp/xR4um49cZKo9olp+ej1L3LYoEglMWIuzMKJ9Jk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agentokratia%2fx402-escrow@2.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":535368},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js","require":"./dist/client/index.cjs"},"./server":{"types":"./dist/server/index.d.ts","import":"./dist/server/index.js","require":"./dist/server/index.cjs"}},"gitHead":"d136a8cce12f77fac0b4c68818e426003e685588","scripts":{"dev":"tsup --watch","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:7e60eefe-f360-42eb-af3e-74f190baf245"}},"repository":{"url":"git+https://github.com/Agentokratia/x402-escrow.git","type":"git","directory":"packages/escrow"},"_npmVersion":"11.9.0","description":"Escrow payment scheme for x402 protocol - session-based payments for high-frequency APIs","directories":{},"_nodeVersion":"22.22.0","dependencies":{"pako":"^2.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","viem":"^2.21.9","@x402/core":"^2.0.0","typescript":"^5.0.0","@types/pako":"^2.0.4","@x402/fetch":"^2.0.0"},"peerDependencies":{"viem":"^2.21.9","@x402/core":"^2.0.0","@x402/fetch":"^2.0.0"},"peerDependenciesMeta":{"@x402/fetch":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/x402-escrow_2.1.1_1770403757825_0.37857502618463457","host":"s3://npm-registry-packages-npm-production"}},"2.1.2":{"name":"@agentokratia/x402-escrow","version":"2.1.2","description":"Escrow payment scheme for x402 protocol - session-based payments for high-frequency APIs","license":"MIT","author":{"name":"Agentokratia"},"repository":{"type":"git","url":"git+https://github.com/Agentokratia/x402-escrow.git","directory":"packages/escrow"},"homepage":"https://github.com/Agentokratia/x402-escrow/tree/main/packages/escrow","bugs":{"url":"https://github.com/Agentokratia/x402-escrow/issues"},"keywords":["x402","escrow","payments","ethereum","base","usdc","erc-3009","session"],"publishConfig":{"access":"public"},"type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client/index.d.ts","import":"./dist/client/index.js","require":"./dist/client/index.cjs"},"./server":{"types":"./dist/server/index.d.ts","import":"./dist/server/index.js","require":"./dist/server/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit"},"peerDependencies":{"@x402/core":"^2.0.0","@x402/fetch":"^2.0.0","viem":"^2.21.9"},"peerDependenciesMeta":{"@x402/fetch":{"optional":true}},"devDependencies":{"@types/pako":"^2.0.4","@x402/core":"^2.0.0","@x402/fetch":"^2.0.0","tsup":"^8.0.0","typescript":"^5.0.0","viem":"^2.21.9"},"dependencies":{"pako":"^2.1.0"},"gitHead":"a8c56ebf4ad72cf544040089a88c46db4f8d42d5","_id":"@agentokratia/x402-escrow@2.1.2","_nodeVersion":"22.22.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-CGkKpMFPZveHSLVnXvRT3YUYKQmBNRluPfCf/Z2P7O9c++Czl7yb+ZGymfqMvnqSx4vxBLMAspdfmXwfrXSGNg==","shasum":"052c556554093a1e1e12701d03fafa4eb3b7a107","tarball":"https://registry.npmjs.org/@agentokratia/x402-escrow/-/x402-escrow-2.1.2.tgz","fileCount":25,"unpackedSize":535865,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@agentokratia%2fx402-escrow@2.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQChBeuWKMr9HTAavAeiN0eL31oEziDvCzYDPolbPEUNXgIhAOVmPrD6WikVegkIuQEvW6UkfAW1mni5M4G0KvI2cAO0"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:7e60eefe-f360-42eb-af3e-74f190baf245"}},"directories":{},"maintainers":[{"name":"panche","email":"panche@agentokratia.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/x402-escrow_2.1.2_1770404849451_0.2500314532570507"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-26T17:43:18.680Z","modified":"2026-02-06T19:07:29.877Z","2.0.0":"2025-12-26T17:43:19.093Z","2.0.1":"2025-12-28T21:51:14.373Z","2.1.0":"2026-02-06T17:10:39.160Z","2.1.1":"2026-02-06T18:49:18.048Z","2.1.2":"2026-02-06T19:07:29.601Z"},"bugs":{"url":"https://github.com/Agentokratia/x402-escrow/issues"},"author":{"name":"Agentokratia"},"license":"MIT","homepage":"https://github.com/Agentokratia/x402-escrow/tree/main/packages/escrow","keywords":["x402","escrow","payments","ethereum","base","usdc","erc-3009","session"],"repository":{"type":"git","url":"git+https://github.com/Agentokratia/x402-escrow.git","directory":"packages/escrow"},"description":"Escrow payment scheme for x402 protocol - session-based payments for high-frequency APIs","maintainers":[{"name":"panche","email":"panche@agentokratia.com"}],"readme":"# @agentokratia/x402-escrow\n\nEscrow payment scheme for the x402 protocol. Supports direct USDC payments and cross-token swaps.\n\n## Features\n\n- **Direct USDC payments** - Gasless via ERC-3009 ReceiveWithAuthorization\n- **Multi-token support** - Pay with WETH, DAI, USDT. Receiver gets USDC.\n- **Automatic swap quotes** - Server fetches DEX quotes, client just signs\n- **Gzip compression** - Aggregator calldata compressed for smaller payloads\n\n## Installation\n\n```bash\nnpm install @x402/core @x402/next @x402/fetch @x402/evm @agentokratia/x402-escrow viem\n```\n\n## Server Integration\n\n### Next.js with paymentProxy\n\n```typescript\nimport { x402ResourceServer, HTTPFacilitatorClient } from '@x402/core/server';\nimport { ExactEvmScheme } from '@x402/evm/exact/server';\nimport { EscrowScheme } from '@agentokratia/x402-escrow/server';\nimport { paymentProxy } from '@x402/next';\n\nconst facilitator = new HTTPFacilitatorClient({\n  url: 'https://facilitator.agentokratia.com',\n  createAuthHeaders: async () => ({\n    verify: { Authorization: `Bearer ${process.env.X402_API_KEY}` },\n    settle: { Authorization: `Bearer ${process.env.X402_API_KEY}` },\n  }),\n});\n\nconst escrow = new EscrowScheme({ facilitator });\n\nconst USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';\n\nconst server = new x402ResourceServer(facilitator)\n  .register('eip155:8453', new ExactEvmScheme())\n  .register('eip155:8453', escrow);\n\n// Auto-discovers supported tokens (USDC, WETH, DAI...)\nconst escrowAccepts = await escrow.buildAccepts({\n  network: 'eip155:8453',\n  price: '$0.01',\n  payTo: '0xYourWallet...',\n  asset: USDC, // settlement token (default: auto-detect)\n});\n\nexport const middleware = paymentProxy(\n  {\n    '/api/premium': {\n      accepts: [\n        { scheme: 'exact', network: 'eip155:8453', price: '$0.01', payTo: '0xYourWallet...' },\n        ...escrowAccepts,\n      ],\n    },\n  },\n  server\n);\n```\n\n### Express with paymentMiddleware\n\n```typescript\nimport { paymentMiddleware } from '@x402/express';\nimport { x402ResourceServer, HTTPFacilitatorClient } from '@x402/core/server';\nimport { EscrowScheme } from '@agentokratia/x402-escrow/server';\n\nconst facilitator = new HTTPFacilitatorClient({\n  url: 'https://facilitator.agentokratia.com',\n  createAuthHeaders: async () => ({\n    verify: { Authorization: `Bearer ${process.env.X402_API_KEY}` },\n    settle: { Authorization: `Bearer ${process.env.X402_API_KEY}` },\n  }),\n});\n\nconst escrow = new EscrowScheme({ facilitator });\nconst accepts = await escrow.buildAccepts({\n  network: 'eip155:8453',\n  price: '$0.01',\n  payTo: '0xYourWallet',\n});\n\napp.use(\n  paymentMiddleware(\n    {\n      'GET /api/analyze': { accepts },\n    },\n    new x402ResourceServer(facilitator)\n  )\n);\n```\n\n### Dynamic Pricing (Custom API Routes)\n\nFor endpoints with per-request pricing (like tip-app):\n\n```typescript\nimport { NextRequest, NextResponse } from 'next/server';\nimport { HTTPFacilitatorClient } from '@x402/core/server';\nimport { EscrowScheme, preprocessSwapPayload } from '@agentokratia/x402-escrow/server';\n\nconst facilitator = new HTTPFacilitatorClient({\n  /* config */\n});\nconst escrow = new EscrowScheme({ facilitator, apiKey: process.env.X402_API_KEY });\n\nexport async function GET(request: NextRequest) {\n  const amount = request.nextUrl.searchParams.get('amount');\n  const recipient = request.nextUrl.searchParams.get('to');\n  const paymentSignature = request.headers.get('payment-signature');\n\n  if (!paymentSignature) {\n    // Fetch fresh DEX quotes with buildAcceptsResolved\n    const accepts = await escrow.buildAcceptsResolved({\n      network: 'eip155:8453',\n      price: `$${amount}`,\n      payTo: recipient,\n    });\n\n    const requirements = accepts.map((a) => ({\n      scheme: a.scheme,\n      network: a.network,\n      asset: a.price.asset,\n      amount: a.price.amount,\n      payTo: a.payTo,\n      maxTimeoutSeconds: 600,\n      extra: a.price.extra || {},\n    }));\n\n    const response = NextResponse.json({ message: 'Payment required' }, { status: 402 });\n    response.headers.set(\n      'PAYMENT-REQUIRED',\n      Buffer.from(JSON.stringify(requirements)).toString('base64')\n    );\n    return response;\n  }\n\n  // Process payment\n  const payload = JSON.parse(Buffer.from(paymentSignature, 'base64').toString());\n  const processed = preprocessSwapPayload({ x402Version: 2, ...payload });\n\n  const verifyResult = await facilitator.verify(processed, processed.accepted);\n  if (!verifyResult.isValid) {\n    return NextResponse.json({ error: verifyResult.invalidReason }, { status: 402 });\n  }\n\n  const settleResult = await facilitator.settle(processed, processed.accepted);\n  return NextResponse.json({ success: true, transaction: settleResult.transaction });\n}\n```\n\n## Client Integration\n\n### Balance-Aware Token Selection (Recommended)\n\n```typescript\nimport { wrapFetchWithPayment, x402Client } from '@x402/fetch';\nimport { ExactEvmScheme } from '@x402/evm/exact/client';\nimport { createWalletClient, createPublicClient, http } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\nimport { base } from 'viem/chains';\nimport {\n  EscrowScheme,\n  createBalanceSelector,\n  preferTokenPolicy,\n} from '@agentokratia/x402-escrow/client';\n\nconst WETH = '0x4200000000000000000000000000000000000006';\nconst USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';\n\nconst account = privateKeyToAccount(process.env.PRIVATE_KEY);\n\nconst walletClient = createWalletClient({\n  account,\n  chain: base,\n  transport: http(),\n});\n\nconst publicClient = createPublicClient({\n  chain: base,\n  transport: http(),\n});\n\n// Balance-aware: auto-picks USDC (gasless) or WETH/DAI (swap)\nconst client = new x402Client(createBalanceSelector(publicClient, account.address))\n  .register('eip155:8453', new ExactEvmScheme(account))\n  .register('eip155:8453', new EscrowScheme(walletClient))\n  .registerPolicy(preferTokenPolicy([WETH, USDC]));\n\nconst paidFetch = wrapFetchWithPayment(fetch, client);\n\nconst res = await paidFetch('https://api.example.com/premium');\nconst data = await res.json();\n```\n\n### Simple Setup (Browser with wagmi)\n\n```typescript\nimport { wrapFetchWithPayment, x402Client } from '@x402/fetch';\nimport { ExactEvmScheme } from '@x402/evm/exact/client';\nimport { EscrowScheme } from '@agentokratia/x402-escrow/client';\n\n// With wagmi's useWalletClient\nconst { data: walletClient } = useWalletClient();\n\nconst signer = {\n  address: walletClient.account.address,\n  signTypedData: (msg) => walletClient.signTypedData({ account: walletClient.account, ...msg }),\n};\n\nconst client = new x402Client()\n  .register('eip155:8453', new ExactEvmScheme(signer))\n  .register('eip155:8453', new EscrowScheme(walletClient));\n\nconst paidFetch = wrapFetchWithPayment(fetch, client);\nconst res = await paidFetch('https://api.example.com/premium');\n```\n\n## How It Works\n\n```\nClient                          Server                      Facilitator\n  │                               │                              │\n  │ GET /api/resource             │                              │\n  │──────────────────────────────>│                              │\n  │                               │ buildAccepts()               │\n  │                               │─────────────────────────────>│\n  │                               │ (fetches quotes for swaps)   │\n  │                               │<─────────────────────────────│\n  │   402 + PAYMENT-REQUIRED      │                              │\n  │<──────────────────────────────│                              │\n  │                               │                              │\n  │ User selects token (WETH)     │                              │\n  │ Signs EIP-712 Permit2         │                              │\n  │                               │                              │\n  │ GET + PAYMENT-SIGNATURE       │                              │\n  │──────────────────────────────>│                              │\n  │                               │ verify() + settle()          │\n  │                               │─────────────────────────────>│\n  │                               │   (executes swap on-chain)   │\n  │                               │<─────────────────────────────│\n  │  200 + transaction hash       │                              │\n  │<──────────────────────────────│                              │\n```\n\n## Networks\n\n| Network      | Chain ID | Facilitator                            |\n| ------------ | -------- | -------------------------------------- |\n| Base Mainnet | 8453     | `https://facilitator.agentokratia.com` |\n| Base Sepolia | 84532    | `https://facilitator.agentokratia.com` |\n\n## API\n\n### Client Exports\n\n| Export                    | Description                                       |\n| ------------------------- | ------------------------------------------------- |\n| `EscrowScheme`            | Client scheme for x402Client (takes WalletClient) |\n| `createBalanceSelector`   | Async selector that checks on-chain balances      |\n| `preferTokenPolicy`       | Sync policy that reorders by token preference     |\n| `checkBalance`            | Utility for custom balance checks                 |\n| `signERC3009`             | Sign ERC-3009 authorization                       |\n| `signPermit2TransferFrom` | Sign Permit2 transfer                             |\n| `computePaymentNonce`     | Derive deterministic nonce from payment params    |\n| `PERMIT2_ADDRESS`         | Universal Permit2 contract address                |\n| `decompressCalldata`      | Decompress gzipped aggregator calldata            |\n\n### Server Exports\n\n| Export                  | Description                                       |\n| ----------------------- | ------------------------------------------------- |\n| `EscrowScheme`          | Server scheme for x402ResourceServer              |\n| `HTTPFacilitatorClient` | Re-export from @x402/core/server                  |\n| `preprocessSwapPayload` | Decompress swap calldata before facilitator calls |\n| `compressCalldata`      | Compress aggregator calldata (gzip)               |\n\n## Supported Input Tokens (Base Mainnet)\n\n| Token | Address                                      |\n| ----- | -------------------------------------------- |\n| USDC  | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |\n| WETH  | `0x4200000000000000000000000000000000000006` |\n| DAI   | `0x50c5725949a6f0c72e6c4a641f24049a917db0cb` |\n| USDT  | `0xfde4c96c8593536e31f229ea8f37b2ada2699bb2` |\n\n## License\n\nMIT\n","readmeFilename":"README.md"}