Pay per request with x402
x402 lets an agent buy RPC requests with a single HTTP payment, with no account, dashboard or card. The agent sends a request, gets 402 Payment Required, signs a USDC transfer authorization and sends the request again. BlockReq settles the payment on Base, answers the request, and returns an RPC Endpoint Key in a response header. From then on the agent uses that key like any other RPC endpoint key until the paid requests run out.
BlockReq implements x402 v2 (x402Version: 2), scheme exact on EVM with an EIP-3009 transferWithAuthorization signature. Permit2 payloads are refused. BlockReq settles the payment itself; there is no external facilitator.
Endpoint
https://x402.blockreq.com/<network><network> is the network slug, for example eth-mainnet. Send a JSON-RPC POST. This host is separate from the public endpoints, whose anonymous rate limits do not change.
Price
| Item | Value |
|---|---|
| Payment network | Base mainnet, eip155:8453 |
| Token | USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) |
| One payment | 1 USDC, exactly one block |
| One block | 526,315 RPC requests |
| Validity | 60 days from the payment |
The amount, the payTo address and the token come from the PAYMENT-REQUIRED header of every 402, so a client should read them there instead of hard-coding them. extra.blockreqBlockRequests states the number of requests one block buys.
How to pay
- Send the JSON-RPC request without payment. The answer is
402with a base64PAYMENT-REQUIREDheader (PaymentRequired, spec section 5.1.2). - Sign an EIP-3009 authorization for the offered
amounttopayTo, withvalidBeforeno later thanmaxTimeoutSecondsfrom now. Standard clients do this for you. - Send the same request again with the base64
PaymentPayloadin thePAYMENT-SIGNATUREheader. - On success the answer is the normal JSON-RPC response (
200) with these headers:
| Header | Content |
|---|---|
PAYMENT-RESPONSE | base64 SettlementResponse with the transaction hash, network and payer |
BlockReq-Endpoint-Key | the RPC Endpoint Key, only for a first payment without a key of its own |
The paid request is answered even when the node returns a JSON-RPC error: the payment has settled either way, so read the key from the header on every paid answer.
# 1. Unpaid: 402 and the requirements
curl -si https://x402.blockreq.com/eth-mainnet \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}'The official clients handle steps 1 to 3. This example uses @x402/fetch and @x402/evm:
import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.PAYER_PRIVATE_KEY as `0x${string}`) });
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const response = await fetchWithPayment("https://x402.blockreq.com/eth-mainnet", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_blockNumber", params: [] }),
});
const endpointKey = response.headers.get("BlockReq-Endpoint-Key"); // keep itUse the key
Save the BlockReq-Endpoint-Key value. It is the same kind of key as the one in a dashboard endpoint, so the agent can call the chain hosts with it and does not pay again until the block is used up. A later payment that presents the key tops up the same account instead of creating a new one.
Replays
An authorization can be spent once, so a payment is never charged twice. Sending the same PAYMENT-SIGNATURE again does not serve a second request. BlockReq answers:
HTTP/1.1 200 OK
PAYMENT-RESPONSE: <base64 settlement>
BlockReq-Endpoint-Key: <the key of this payment>
Cache-Control: no-store
{"status":"payment_already_settled","action":"use_endpoint_key"}There is no JSON-RPC result in this body. It is a 200 on purpose: a 402 would make a standard x402 client sign and pay again. If an answer was lost on the way, resend the same signature to get the key back, then use the key.
When the outcome is unclear
If an answer carries "action": "resend_same_signature" (a 402 settlement_pending, or a 503 after a payment attempt), send the same PAYMENT-SIGNATURE again, after Retry-After when given. Do not sign a new authorization: the first one may still execute, and a second signature is a second, separate 1 USDC payment. If the authorization never executes, the replay answers 402 payment_expired and no money moved.
Failures
The body of a failure is {"error": "<code>", "action": "<sign_new | resend_same_signature | retry_later>"}.
| Status | error | action | Meaning |
|---|---|---|---|
| 402 | payment_invalid | sign_new | Wrong shape, signature, amount, payTo or network, or the payer cannot be accepted |
| 402 | payment_expired | sign_new | validBefore passed or is less than 20 seconds away |
| 402 | authorization_window_invalid | sign_new | validAfter is in the future or validBefore is too far ahead |
| 402 | insufficient_funds | sign_new | The payer holds less USDC than the amount |
| 402 | payment_reversed | sign_new | The authorization was cancelled, the transfer reverted, or the credit was reversed |
| 402 | settlement_pending | resend_same_signature | The transaction is not confirmed yet; PAYMENT-RESPONSE carries its hash |
| 429 | anonymous_rate_limited, payer_limited | retry_later | Too many new accounts per hour, or a payer with 3 unconfirmed blocks or repeated reverts |
| 502 | unexpected_settle_error | retry_later | A failure before anything was signed; nothing was charged |
| 503 | settlement_pending, unexpected_settle_error | resend_same_signature | Settlement is still being confirmed |
| 503 | none | retry_later | Settlement is paused; see Retry-After |
A 402 that carries a PAYMENT-REQUIRED header is safe to answer with a new signature; the ones without it are not, because a payment may already be in flight.
Credit and confirmation
A payment credits one block as soon as the transfer is on chain (provisional) and confirms after 30 confirmations. The Dashboard shows the block as a normal request balance. A credit that the chain later reverses is reversed here too.