> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# x402 How It Works

> How the x402 v2 protocol turns an HTTP 402 response into a verified onchain payment, with one round-trip and no signup.

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](https://docs.polygon.technology/payment-services/agentic-payments/x402/guides/migration-v1-to-v2.md).

***

## How it works

x402 payment flow

1
Client
→
Resource Server
GET /endpoint

2
Resource Server
→
Client
402 Payment Required + PaymentRequirements (accepts array)

3
Client
→
Resource Server
Retries with `PAYMENT-SIGNATURE` header

4
Resource Server
→
Facilitator
POST /verify (signature + requirements)

5
Facilitator
→
Polygon
Settles USDC onchain

6
Resource Server
→
Client
200 OK + body + `PAYMENT-RESPONSE` receipt header

> [!TIP]
>
> 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

| 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 an `x402ResourceServer` with a facilitator client. The first unpaid request returns a 402 with an `accepts` array:

```json theme={null}
{
  "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](https://docs.polygon.technology/payment-services/agentic-payments/x402/guides/quickstart-sellers.md).

***

## 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:

```http theme={null}
PAYMENT-SIGNATURE: <base64-encoded payload>
```

* Read the resulting receipt via `x402HTTPClient.getPaymentSettleResponse()` after a successful response.

For setup, see the [x402 Quickstart for Buyers](https://docs.polygon.technology/payment-services/agentic-payments/x402/guides/quickstart-buyers.md).

***

## Facilitator (optional)

The facilitator exposes verification and settlement endpoints:

```http theme={null}
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.

| 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

> [card] [x402 Quickstart for Sellers](https://docs.polygon.technology/payment-services/agentic-payments/x402/guides/quickstart-sellers.md)
>
> Add x402 v2 middleware to Express, Next.js, or Hono.

> [card] [x402 Quickstart for Buyers](https://docs.polygon.technology/payment-services/agentic-payments/x402/guides/quickstart-buyers.md)
>
> Pay x402-protected endpoints programmatically.

> [card] [Migration: V1 to V2](https://docs.polygon.technology/payment-services/agentic-payments/x402/guides/migration-v1-to-v2.md)
>
> Upgrade an existing V1 integration to v2.

> [card] [Mainnet Facilitator Addresses](https://docs.polygon.technology/payment-services/agentic-payments/x402/analytics.md)
>
> Signer addresses for the Polygon mainnet and Amoy facilitators.
