x402 is a payment protocol built on the HTTPDocumentation Index
Fetch the complete documentation index at: https://docs.faremeter.xyz/llms.txt
Use this file to discover all available pages before exploring further.
402 Payment Required status code. It enables programmatic payments between any HTTP client and server without accounts, sessions, or custom authentication.
The payment flow
- Client — Makes requests and signs payments locally. Never talks to the facilitator directly.
- Resource Server — Protects endpoints with middleware. Makes two API calls to the facilitator (
POST /acceptsandPOST /settle) but never holds keys or interacts with the blockchain. - Facilitator — Verifies payment proofs and settles transactions on-chain. Handles all blockchain interaction.
- Blockchain — The settlement layer (Solana or EVM).
Step by step
1. Initial request The client makes a standard HTTP request to a protected resource./accepts endpoint with partial payment requirements. The facilitator enriches them with blockchain-specific details:
- Solana: Fee payer address, token decimals, recent blockhash
- EVM: EIP-712 domain parameters (name, version, chainId, verifyingContract)
402 Payment Required with the enriched requirements in the response body:
- Solana: Creates and partially signs a transaction that transfers tokens to the merchant
- EVM: Signs an EIP-3009
transferWithAuthorizationusing EIP-712 typed data
X-PAYMENT; v2 uses PAYMENT-SIGNATURE. See Protocol Versions for the full header mapping.
5. Verification and settlement
The server’s middleware calls the facilitator’s /settle endpoint with the payment header and the original requirements. The facilitator:
- Validates the payment payload structure
- Verifies cryptographic signatures
- Checks amounts, addresses, and nonces
- Submits the transaction on-chain:
- Solana: Co-signs as fee payer and submits to Solana RPC
- EVM: Calls
transferWithAuthorizationon the token contract and pays gas
- Returns
{ success: true, transaction, network }
Legacy v1 implementations may return these fields as
txHash and networkId. Spec-compliant v1 and v2 both use transaction and network. See Protocol Versions for details.200 OK response.
If a payment settles but the client loses the connection before receiving the
full response, retrying the request would trigger a second charge. To avoid
this, design your server to grant time-limited access upon payment rather than
delivering the resource in a single response. This lets the client retry or
resume without paying again.
Payment requirements
A payment requirement describes what the server accepts. Key fields:| Field | Description |
|---|---|
scheme | Payment method (e.g., "exact") |
network | Blockchain network identifier on the wire (e.g., "solana-devnet", "base-sepolia"). The @faremeter/info helpers accept shorter cluster names like "devnet" and expand them automatically. |
asset | Token to pay with (e.g., "USDC") |
maxAmountRequired | Maximum payment amount (in smallest unit) |
payTo | Recipient address |
resource | The URL being paid for |
maxTimeoutSeconds | How long the payment proof is valid |
Payment payload
TheX-PAYMENT header contains a base64-encoded JSON object:
| Field | Description |
|---|---|
x402Version | Protocol version (1 or 2) |
scheme | Which scheme was used |
network | Which network was used |
payload | Scheme-specific proof (signatures, transaction data) |
Protocol versions
x402 version 1 sends the payment proof in theX-PAYMENT header as a base64-encoded JSON payload. Version 2 uses the PAYMENT-SIGNATURE header instead, aligning with the evolving x402 specification. Version 2 is preferred for new integrations. Faremeter supports both versions. See the Protocol Versions guide for a detailed comparison and migration instructions.
Further reading
- Facilitators — How payment verification and settlement works.
- Payment Schemes — The specific payment methods available.