x402_url — a payment endpoint an AI agent or x402 client can pay programmatically. Paying it authorizes a gasless USDC payment on Base (EIP-3009); Coinbase then captures and settles it server-side, with no hosted page, wallet pop-up, or human required. This guide walks through the end-to-end flow: create a checkout, pay its x402_url as an agent, and confirm the checkout completes.
Checkouts use an authorize-then-capture flow. Paying the
x402_url authorizes (escrows) the funds; Coinbase captures and settles them server-side. Treat the checkout reaching COMPLETED as the source of truth for settlement — see Confirm settlement.Prerequisites
- A Coinbase Business account with a CDP API key. See Authentication.
- On the paying (agent) side: a CDP account and API keys, and a wallet funded with USDC on Base. The examples below use
CdpX402Client, which provisions and signs with a CDP-managed wallet, so no raw private keys are needed. - Node.js and npm.
1. Create a checkout
Create a checkout with the Create Checkout endpoint. Authenticate with a JWT Bearer token signed with your CDP API key secret; therat#view scope is required (see Authentication).
url (for humans) and an x402_url (for agents):
2. Pay the x402_url as an agent
Point an x402 client at the x402_url. It is a POST endpoint: the first request returns 402 Payment Required with the payment requirements, and the client retries with the signed payment. With @x402/fetch, wrapFetchWithPayment handles that challenge-and-retry automatically.
1
Install the client packages
2
Pay the checkout
CdpX402Client defaults to Base mainnet. To test on Base Sepolia, construct it with new CdpX402Client({ environment: "development" }) (or set CDP_X402_CLIENT_ENVIRONMENT=development; the explicit option takes precedence). Only fund the address with the amount you intend to pay.ACTIVE → PROCESSING → COMPLETED. Confirm the checkout reaches COMPLETED (next step) rather than treating the HTTP response alone as final.
Prefer to pay as a human instead? Open the checkout’s hosted url in a browser, connect a wallet on Base, and approve the (gasless) USDC authorization.
3. Confirm settlement
After the agent authorizes, the checkout transitionsACTIVE → PROCESSING → COMPLETED as Coinbase captures the funds. Poll the Get Checkout endpoint until it reaches a terminal status:
status is COMPLETED and transactionHash holds the on-chain settlement transaction. If the payment cannot be captured, the checkout ends FAILED and any authorization hold is released when the capture window expires. You can also subscribe to webhooks for real-time notifications instead of polling.
Refunds
ACOMPLETED or PARTIALLY_REFUNDED checkout can be refunded (fully or partially, up to the remaining amount) with the Refund Checkout endpoint. Refunds are asynchronous — poll the checkout to watch refundedAmount and status (REFUNDED or PARTIALLY_REFUNDED).