Skip to main content
x402 turns the HTTP 402 status code into a real payment channel. A client requests a paid resource, the server responds with a price and a payment requirement, the client signs and retries with a payment header, the server verifies (locally or through a facilitator) and settles onchain, then returns the resource with a receipt. The whole exchange is two HTTP round-trips and no signup, API key, or contract. Polygon’s mainnet and Amoy facilitators run x402 v2. If you have a V1 integration, see Migration: V1 to V2.

How it works

x402 payment flow
1ClientResource ServerGET /endpoint
2Resource ServerClient402 Payment Required + PaymentRequirements (accepts array)
3ClientResource ServerRetries with PAYMENT-SIGNATURE header
4Resource ServerFacilitatorPOST /verify (signature + requirements)
5FacilitatorPolygonSettles USDC onchain
6Resource ServerClient200 OK + body + PAYMENT-RESPONSE receipt header
Steps 2 and 3 collapse into a single call if the client already knows the route’s price ahead of time (for example, from a manifest). The signed payment header travels with the first request.

Protocol resources

ResourceRole
ClientRequests a resource and signs the payment (browser, agent, SDK)
Resource ServerProtects endpoints, issues 402, verifies payment payloads
FacilitatorOptional verification + onchain settlement layer (Polygon: x402.polygon.technology mainnet, x402-amoy.polygon.technology Amoy)
Payment SchemeDefines chain, token, network, format (exact or upto)
PaymentRequirementsaccepts array in the 402 body: scheme, network, amount, description
PAYMENT-SIGNATURE headerSigned payment payload on the retry request
PAYMENT-RESPONSE headerBase64-encoded receipt with the settlement transaction hash

Server side (sellers)

Protect routes with v2 middleware that pairs an x402ResourceServer with a facilitator client. The first unpaid request returns a 402 with an accepts array:
{
  "x402Version": 2,
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:137",
      "maxAmountRequired": "1000",
      "description": "Access to premium API"
    }
  ],
  "error": null
}
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 one accepts entry, signs against its wallet, and retries with the payment header.
  • Create an x402Client, register ExactEvmScheme for "eip155:*".
  • Use wrapFetchWithPayment or wrapAxiosWithPayment to handle 402s transparently.
  • The signed payload becomes a base64 string on the retry:
PAYMENT-SIGNATURE: <base64-encoded payload>
  • Read the resulting receipt via x402HTTPClient.getPaymentSettleResponse() after a successful response.
For setup, see the x402 Quickstart for Buyers.

Facilitator (optional)

The facilitator exposes verification and settlement endpoints:
POST /verify
{
  "x402Version": 2,
  "paymentHeader": "<payload>",
  "paymentRequirements": { ... }
}
Some facilitators settle each payment instantly; others batch settlements for high-volume sellers. Polygon’s facilitators settle instantly on mainnet and Amoy.
NetworkFacilitator URL
Polygon mainnethttps://x402.polygon.technology
Polygon Amoyhttps://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.