How to Use x402 to Transact with Bots

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.

What you get for 0.5 USDC

Agents: send Accept: application/json for a typed payload. Unauthenticated calls receive HTTP 402 with x402 v2 payment requirements.

Fetch full article (0.5 USDC)JSONFree metadataGET /api/public/article/how-to-use-x402-to-transact-with-bots/full

Questions this article answers

Full answers included in the paid body.