How it works
Protocol resources
| Resource | Role |
|---|---|
| Client | Requests a resource and signs the payment (browser, agent, SDK) |
| Resource Server | Protects endpoints, issues 402, verifies payment payloads |
| Facilitator | Optional verification + onchain settlement layer (Polygon: x402.polygon.technology mainnet, x402-amoy.polygon.technology Amoy) |
| Payment Scheme | Defines chain, token, network, format (exact or upto) |
PaymentRequirements | accepts array in the 402 body: scheme, network, amount, description |
PAYMENT-SIGNATURE header | Signed payment payload on the retry request |
PAYMENT-RESPONSE header | Base64-encoded receipt with the settlement transaction hash |
Server side (sellers)
Protect routes with v2 middleware that pairs anx402ResourceServer with a facilitator client. The first unpaid request returns a 402 with an accepts array:
maxAmountRequired is in the smallest unit of the currency. USDC has six decimals, so 1000 = $0.001. On retry, verify the PAYMENT-SIGNATURE against the facilitator and respond 200 OK with a PAYMENT-RESPONSE header carrying the receipt.
For setup, see the x402 Quickstart for Sellers.
Client side (buyers)
The buyer sends the initial request, reads the 402, picks oneaccepts entry, signs against its wallet, and retries with the payment header.
- Create an
x402Client, registerExactEvmSchemefor"eip155:*". - Use
wrapFetchWithPaymentorwrapAxiosWithPaymentto handle 402s transparently. - The signed payload becomes a base64 string on the retry:
- Read the resulting receipt via
x402HTTPClient.getPaymentSettleResponse()after a successful response.
Facilitator (optional)
The facilitator exposes verification and settlement endpoints:| Network | Facilitator URL |
|---|---|
| Polygon mainnet | https://x402.polygon.technology |
| Polygon Amoy | https://x402-amoy.polygon.technology |
Design goals
- HTTP-native. Uses standard status codes and headers. No additional protocol layer.
- Chain and token agnostic. Works across any chain or stablecoin.
- Minimal integration. Middleware on the server side; a few wrappers on the buyer side.
- Micropayments. Low friction and low cost, suitable for per-request pricing.
- Autonomous agents. AI systems can transact without per-transaction human approval.
Implementation
x402 Quickstart for Sellers
Add x402 v2 middleware to Express, Next.js, or Hono.
x402 Quickstart for Buyers
Pay x402-protected endpoints programmatically.
Migration: V1 to V2
Upgrade an existing V1 integration to v2.
Mainnet Facilitator Addresses
Signer addresses for the Polygon mainnet and Amoy facilitators.