How it works
Protocol resources
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: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.