💳Intermediate⏱ 45 min
x402 Payment Protocol Deep Dive
The x402 protocol extends HTTP with a 402 Payment Required flow. When a client hits a gated endpoint, the server returns a 402 with payment details. The client pays on-chain and retries with a receipt. This quest walks through the entire flow from scratch.
x402usdcpaymentsexpressbase-l2
Prerequisites:Your First Agent on Base
🏆
Ability to build and monetize any HTTP endpoint with x402 payments
Step 1: Understand the 402 handshake
A 402 response tells the client how much to pay, to which address, on which chain. The client uses `x402-fetch` or a compatible library to pay and retry.
Step 1 — json
// What a 402 response looks like
{
"x402Version": 1,
"accepts": [{
"scheme": "exact",
"network": "base-mainnet",
"maxAmountRequired": "10000", // 0.01 USDC (6 decimals)
"resource": "https://hub.d0xeddev.com/api/hub-data",
"description": "Hub data feed",
"mimeType": "application/json",
"payTo": "0xYourPaymentAddress",
"maxTimeoutSeconds": 300,
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"extra": { "name": "USDC", "version": "2" }
}]
}✓
Checkpoint
Can describe the 402 handshake in your own words
1 / 3
