Why x402 matters for bots
x402 revives the long-dormant HTTP 402 status code as a machine-native payment
handshake. Any resource can respond 402 PAYMENT-REQUIRED with a JSON body that
tells the caller exactly what to pay, on which chain, to which address, and how
to prove it. Autonomous agents can settle micropayments in USDC on Base in a
single retry, with no user in the loop, no API keys, and no accounts.
This guide walks a bot developer through the entire loop end to end: reading a
402 challenge, signing an EIP-3009 authorization with viem, retrying with the
X-PAYMENT header, and verifying the settlement receipt returned in
X-PAYMENT-RESPONSE. Every step is shown as a runnable TypeScript block.