x402
x402 Payments
x402 is an open-source protocol that turns the dormant HTTP 402 Payment Required status code into a fully-featured, on-chain payment layer for APIs, websites, and autonomous agents.
x402 Playground
Try out x402 payments in our live playground
The thirdweb x402 client/server stack supports payments on 170+ EVM chains.
The payment token must support either:
- ERC-2612 permit (most ERC20 tokens)
- ERC-3009 sign with authorization (USDC on all chains)
useFetchWithPayment is a React hook that automatically handles 402 Payment Required responses with built-in UI for payment errors and wallet connection:
The hook automatically shows modals for wallet connection, funding and payment errors. See the client side docs for more details.
To make your API calls payable, use the settlePayment function in a middleware or endpoint:
You can also create middlewares to handle payment for multiple endpoints, see the server side docs for more details. The facilitator handles settling the payment onchain using your own server wallet.