x402 Protocol Guide
x402 is an open internet-native payment standard that revives the dormant HTTP 402 'Payment Required' status code, enabling direct blockchain-based transactions over HTTP.
Payment Flow
Complete payment lifecycle in 6 steps
HTTP Request
ClientBrowser or AI agent initiates API request
402 Payment Required
ServerServer responds with PAYMENT-REQUIRED header containing price, currency, network, and recipient address
Payment Payload Generation
ClientClient creates EIP-3009 signed payment payload, resubmits via X-PAYMENT header
Payment Verification
FacilitatorFacilitator validates signature, amount, address, and balance (~100ms)
On-Chain Settlement
BlockchainFacilitator submits transaction (≈2 seconds finality on Base)
Resource Delivery
ServerServer returns 200 OK with PAYMENT-RESPONSE header containing transaction confirmation
HTTP Header Specification
Three key headers used in the x402 protocol
PAYMENT-REQUIREDStep 2Included in the 402 response from the server. Base64-encoded JSON containing scheme, network, amount, recipient address, and resource information.
X-PAYMENTStep 3Attached by client on retry. Contains x402 version, scheme, network, and EIP-3009 authorization details (signature, from/to addresses, amount, validity period, nonce).
PAYMENT-RESPONSEStep 6Returned by server on success. Contains payment status and transaction hash.
EIP-3009: Transfer With Authorization
x402 leverages EIP-3009 to enable gasless USDC transfers.
Users only need USDC — no ETH/SOL required
Signatures generated off-chain — no gas costs for signing
validBefore/validAfter parameters control signature lifespan
Unique nonce prevents replay attacks
Solidity Interface