Learn x402: Internet-Native Payments
Enable instant, automatic stablecoin payments directly over HTTP. Monetize APIs and digital content without accounts, sessions, or complex authentication.
Built for Modern Internet Commerce
x402 enables new business models that were previously impossible or impractical with traditional payment systems.
How x402 Works
A simple request-response flow with programmatic payments built directly into HTTP.
Client Requests Resource
A client (human or AI agent) makes an HTTP request to access a protected API endpoint or content.
GET /api/weather HTTP/1.1
Server Returns 402
If payment is required, the server responds with HTTP 402 Payment Required with payment requirements in the response body.
HTTP/1.1 402 Payment Required
Content-Type: application/json
{"accepts": [{"paymentRequirements": {...}}]}Client Sends Payment
The client constructs a payment payload (base64-encoded JSON) with blockchain transaction details and retries the request.
GET /api/weather X-PAYMENT: eyJ4NDAyVmVyc2lvbiI6IjAuNy4wIi4uLg==
Server Verifies & Responds
The server verifies the payment via the facilitator. If valid, it returns the requested resource.
HTTP/1.1 200 OK
{"weather": "sunny"}Try It Yourself
Experience the x402 payment flow in a safe sandbox environment. No real payments required.
Implementation Examples
Get started quickly with these code examples for popular frameworks.
# Step 1: Initial request to protected endpoint
curl -i https://api.example.com/weather
# Response: HTTP 402 Payment Required
# {
# "accepts": [{
# "paymentRequirements": {
# "scheme": "exact",
# "network": "base-sepolia",
# "amount": "0.001",
# "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
# "destination": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
# }
# }]
# }
# Step 2: Make payment on-chain and construct payload
# Payment payload (before base64 encoding):
# {
# "x402Version": "0.7.0",
# "scheme": "exact",
# "network": "base-sepolia",
# "payload": { "txHash": "0xabc123...", ... }
# }
# Step 3: Retry request with X-PAYMENT header (base64-encoded)
curl -i https://api.example.com/weather \
-H "X-PAYMENT: eyJ4NDAyVmVyc2lvbiI6IjAuNy4wIiwic2NoZW1lIjoiZXhhY3QiLi4ufQ=="
# Response: HTTP 200 OK with X-PAYMENT-RESPONSE header
# {
# "weather": "sunny",
# "temperature": 72
# }Protocol Details: The X402 protocol uses the X-PAYMENT header with base64-encoded JSON payloads for payment submission, and X-PAYMENT-RESPONSE for settlement confirmation. Payment requirements are sent in the 402 response body.
Middleware: The x402 middleware packages automatically handle base64 encoding, header formatting, and facilitator communication so you don't have to implement the low-level protocol details.
Note: These examples use the Base Sepolia testnet facilitator. For production, use the mainnet facilitator from Coinbase CDP.
Built with Security in Mind
x402 leverages blockchain security while maintaining simplicity and privacy.
- Testnet-only transactions (Base Sepolia)
- No real money involved in demo
- Isolated sandbox environment
- Rate limiting and abuse prevention
- Educational purposes only
Resources & Documentation
Everything you need to start building with x402.