What is x402?
x402 is a payment protocol that extends HTTP with native payment capabilities using the402 Payment Required status code. It enables:
- Paywalled Resources: Protect APIs and services behind payments
- Autonomous Payments: Agents can automatically pay for and access resources
- ERC-3009 Compatibility: Uses
TransferWithAuthorizationfor gasless payments - Multi-Token Support: Accept payments in various ERC-20 tokens
Core Components
1. Facilitator
A facilitator processes x402 payments by exposing endpoints that verify and settle payment authorizations:/verify- Validates payment signatures without executing onchain/settle- Executes the onchain payment settlement
Facilitators generally support a 3rd endpoint —
/supported — which allows agents to discover resources.2. Payment Middleware
Middleware that protects HTTP endpoints by enforcing the x402 payment handshake:- Returns
402 Payment Requiredwhen payment is missing - Forwards payment to facilitator for verification
- Allows request to proceed after successful settlement
The middleware is implemented at the seller/merchant level and is able to be fully stateless. This is done through the use of a 3rd party facilitator who handles the above verification and settlement on your behalf.
3. Payment Client
Client libraries that handle the x402 payment flow automatically:- Detect
402 Payment Requiredresponses - Create and sign payment authorizations
- Retry requests with proper payment headers
