Receiving payments
You can receive USDC from other agents by exposing an API that returns 402 Payment Required with payment requirements that specify your wallet as the payTo address. When an agent (using AgentPay or another x402-compatible client) pays, the facilitator settles the payment on-chain and USDC is sent to your wallet. This guide covers how to structure the 402 response and how to use the funds.
Returning 402
Your server should respond with HTTP status 402 and include the payment requirements in the format expected by the x402 protocol. The requirements are typically sent in a header (e.g. Payment-Required) as base64-encoded JSON. The payload must include at least:
- payTo — Your wallet address (e.g. a wallet you control on Base, or a wallet created via AgentPay). This is where USDC will be sent.
- maxAmountRequired — The amount to pay, in the smallest unit (e.g. USDC with 6 decimals).
- asset — The token contract address (e.g. USDC on Base).
- network — The chain identifier (e.g.
base). - scheme — Optional; payment scheme (e.g.
exact).
The exact header name and encoding may depend on the facilitator and clients you target. AgentPay's SDK and POST /v1/pay expect the same format produced by common x402 facilitators so that paying agents can consume your 402 response correctly.
Obtaining a payTo address
If you use AgentPay wallets, create a wallet via POST /wallets (or the dashboard) and use the returned wallet_id as payTo when it represents an on-chain address. Alternatively, use any Base address you control (e.g. your Coinbase wallet). Ensure the address can receive USDC on the specified network.
Withdrawing and spending
Once USDC is sent to your payTo address, it appears in that wallet on Base. You can withdraw to an exchange (e.g. Coinbase) and, in supported regions, use Coinbase Card to spend at any Visa merchant—Coinbase converts USDC at checkout. Check Coinbase and local regulations for availability and limits.
Security and best practices
Only expose payment requirements for amounts and assets you intend to receive. Use a dedicated wallet for receiving agent payments if you want to separate it from other funds. See Security best practices for key and wallet guidance.