x402-make-payments
Example payment client — wraps fetch to pay for HTTP-gated resources automatically, the way an autonomous agent would.
402, and pays for it automatically with no human in the loop.
The client holds its own signing key, so it pays as the participant that key belongs to. That is how the 402 flow works — it checks the signature, not who is behind the software. Establishing who is answerable when software spends for someone else is Know Your Agent, a separate question.
Prerequisites
Node.js 20+
Node.js 20+
npm is included with Node.js.Verify:
A funded testnet wallet for your agent
A funded testnet wallet for your agent
Your agent needs a wallet that holds the source token (e.g. USDC on Base Sepolia) on the chain the merchant accepts.Export its private key — use a testnet-only wallet, never one holding real funds. See Set up a testnet wallet.If you are testing locally against the merchant’s in-process stub facilitator, any private key will work since no real transaction is submitted.
Permit2 allowance (testnet / mainnet only)
Permit2 allowance (testnet / mainnet only)
For real on-chain settlement, the Permit2 contract must be approved to spend your source token.Run this once on the source chain:Skip this step when testing locally — the stub facilitator does not check allowances.
Prerequisites for real settlement
Local stub runs need no funds. Before you point the client at testnet or mainnet, confirm your payer wallet has the source token, native gas for the one-time Permit2approve(), and an active allowance — see Prerequisites.
1. Clone and install
2. Configure
PRIVATE_KEY in .env to your agent wallet’s 0x-prefixed key — it’s the only value you need to run against the local merchant in stub mode.
The client’s other variables (MERCHANT_URL, RPC_URL) are documented in the example README; the corridor itself is the merchant’s config, not the client’s.
3. Start the merchant (if running locally)
Follow Agentic receives to start the example merchant first — it runs an in-process stub facilitator, so there’s nothing else to start:The merchant is a separate app, so it needs its own
npm install (the clone step only installed x402-make-payments). To install all four example apps at once instead, run npm run install:all from the repo root.4. Run the client
Back inx402-make-payments:
What’s happening
Looking atsrc/client.ts and src/purchase.ts:
registerAtumEscrowSchemeteaches the x402 client how to construct and sign Atum-scheme payment credentials.wrapFetchWithAtumPaymentwraps the nativefetch— your agent calls it with a purchase identifier (paymentIdentifier) so every re-attempt names the same payment.- On
402, the wrapper reads the payment requirements, signs a Permit2 authorization, and retries once withPAYMENT-SIGNATURE—wrapFetchWithAtumPaymentitself makes exactly that one attempt and returns, whatever the outcome. It does not loop. - The retry-until-settled behavior is a layer above it:
src/purchase.ts’spayPurchase()is application code that calls the wrappedfetchin a loop, re-attempting the same purchase (fresh402, re-signed credential, samepaymentIdentifier) every few seconds while the response reportssettlement_pending, until settlement reaches a terminal outcome.src/client.tswires the two together —payPurchase(() => pay(...)). Integrating directly against the SDK instead of reusing this example means writing your own version of that loop. See Idempotency.
settle.
Going to testnet or mainnet
Real settlement means funding your agent’s wallet, approving the source token (Permit2), and pointing both merchant and client at Atum-provided URLs. See the example README for.env values, funding amounts, and on-chain verification — its Going to testnet or mainnet section walks through that app. New to Atum’s environments? See Choose an environment for which one to target and what to expect from production-testnet. Run through the pre-flight checklist before your first real payment.