Agents are good at deciding what data they need. They’ve learned to do what humans do – sign up for accounts, store API keys, manage credit cards – but this is far from ideal. Imitating humans is error prone, introduces unnecessary security risks, and simply copies economic inefficiencies.

Why sign up for an API subscription if only a little data is needed now? Why pay for more than you can use because you might need it later, or because the vendor doesn’t give you any other options? Why can’t an agent decide where to buy data each time it needs some?

x402 is an open payment standard that fixes this. No signups, no API key, no credit cards. Each transaction is independent of all others. It’s a payment standard that is completely in line with our emerging agentic economy.

This post explains the standard in plain terms and then shows how Testril, our pay-per-call blockchain indexer for agents, uses it.

x402 in one minute

x402 takes its name from HTTP status code 402, "Payment Required", which was reserved decades ago and barely used. The standard turns it into a simple handshake:

There are no accounts and no API keys. The standard is network-agnostic and transport-agnostic: the same messages can travel over plain HTTP or inside an agent protocol such as MCP. It also supports more than one payment "scheme". exact pays one quote with one transfer. batch-settlement lets a buyer deposit once and then sign cheap vouchers for many small payments.

How Testril uses it

Testril is an MCP server, so agents talk to it through tool calls, not raw HTTP. It speaks x402's MCP form directly: a paid tool is paid on the call itself, and a standard x402 client can pay it.

  1. Ask for the work and get a quote. An agent calls materialize (index a block range) or read (fetch indexed data). If payment is due, the call returns an MCP error result. Its structuredContent and first content block hold x402 PaymentRequired, including the accepted payment options; its second content block holds Testril's itemised {quote_id, amount, lines} quote. Nothing has been computed or charged yet. The quote freezes the price and the work for 120 seconds. A materialize quote also lists holes: each missing block range and the Bound Functions whose gaps require it.

  2. Repeat the call with the payment. The agent signs one of the offered options and sends the same call and arguments again, with the signed x402 payment in _meta["x402/payment"]. Testril verifies and settles it through an x402 facilitator and does the work in that same call, returning the receipt in _meta["x402/payment-response"]. There's no separate pay step and no payment ID to carry around. A retried call with the same spent payment or x402 payment-identifier is served again without a second charge; reusing an identifier for different work is refused as payment_identifier_conflict.

A paid materialize answers materializing straight away with a job handle; the agent follows it with inspect until it's done. A paid read returns its rows directly. If you use Testril from Claude Code, Codex or Grok Build, the published testril CLI holds your key and pays within budgets you set.

Here is an illustrative exchange for a 15-block materialize. Amounts are in USDC atoms (1 USDC = 1,000,000 atoms); IDs and addresses are placeholders.

// 1. request (illustrative)
{ "tool": "materialize",
  "arguments": { "bound_function_id": "sha256:<id>", "from_block": 1000, "to_block": 1015 } }

// 1. response: x402 payment required (isError: true; illustrative)
{ "isError": true,
  "structuredContent": {
    "x402Version": 2,
    "error": "payment_required",
    "resource": { "url": "mcp://tool/materialize", "mimeType": "application/json" },
    "accepts": [ {
      "scheme": "batch-settlement",
      "network": "<CAIP-2 network>",
      "asset": "<USDC address>",
      "payTo": "<receiver>",
      "amount": "1800",
      "maxTimeoutSeconds": 3600,
      "extra": { "name": "USDC", "version": "2", "minDeposit": "10000",
                 "receiverAuthorizer": "<address>", "withdrawDelay": 3600 } } ] },
  "content": [
    { "type": "text", "text": "<the PaymentRequired JSON above>" },
    { "type": "text", "text": "{\"quote_id\":\"quote:<uuid>\",\"amount\":{\"atoms\":\"1800\",\"usd\":\"$0.0018\"},\"lines\":[{\"label\":\"materialize_blocks\",\"units\":15,\"unit_price\":{\"atoms\":\"120\",\"usd\":\"$0.00012\"},\"amount\":{\"atoms\":\"1800\",\"usd\":\"$0.0018\"}}]}" }
  ] }

// 2. the same call again, with the signed payment attached
{ "tool": "materialize",
  "arguments": { "bound_function_id": "sha256:<id>", "from_block": 1000, "to_block": 1015 },
  "_meta": { "x402/payment": { "x402Version": 2, "accepted": { /* the accepts row, copied whole */ },
                               "payload": { /* signature */ } } } }

// 2. response: the work starts, with an x402 receipt
{ "outcome": "success", "result": "materializing",
  "job": { "job_id": "job:<id>", "quote_id": "quote:<uuid>", "blocks_total": 15, "state": "running" },
  "_meta": { "x402/payment-response": { "success": true, "network": "<CAIP-2 network>", "payer": "0x<wallet>" } } }

If settlement may have happened but Testril could not finish recording the purchase, the result is outcome: "error" with kind: "payment_recovery_pending" and a payment summary. Do not sign a new payment. Retry the original paid call; Testril retains it and retries completion even after restart. Quote expiry alone does not settle an unknown outcome.

The bound function's REST data URL uses the HTTP spelling of the same flow: unpaid GET returns 402 with PAYMENT-REQUIRED and the quote body; paid GET sends the base64 JSON PaymentPayload in PAYMENT-SIGNATURE and receives PAYMENT-RESPONSE.

What things cost

Rates are stated in US dollars. A call can settle in USDC or use operator-granted usage credits; its receipt identifies the currency that actually paid. Today's published rates are:

These are currently hard-coded amounts that mirror industry standards for index creation and data reads, but they will soon be much more dynamic and mirror actual costs. Pre-AI this wasn’t possible, but when agents manage costs and are able to price small amounts of work on a continuous basis, the impossible becomes possible. Early modeling indicates that our hard-coded fees are too high!

Even today, most of these amounts are far below a cent. For a wallet paying in USDC, an offered exact option makes one transfer for the quote. batch-settlement lets the agent deposit at least $0.01 of USDC into escrow once, then sign a cheap voucher for each call, and Testril collects many vouchers in one onchain transaction. Read the call's actual accepts rows: the offered settlement options are deployment- and request-specific.

The NFT: cache, earnings and claims

Your first materialization purchase on a payment network starts a claim-right NFT there: a transferable ERC-721 that records your purchases and what you've earned. It is minted just after your purchase is served, so your data never waits for it. If you sell the NFT, its history goes with it, and your next purchase on that network creates a new one.

When you index a range, you're supplying data that other agents may want. When someone later pays to read blocks you cached, part of the per-block read fee is credited to you and another slice extends how long your cache is kept. A share is USDC only when both that read and your materialization purchase were paid in USDC; otherwise it is usage credits. Popular data stays cached and keeps earning. Data nobody reads expires.

The NFT shows lifetime totals by currency: paid, refunded, cost, earned, claimed, unclaimed and profit and loss. You collect earnings with claim_rewards, naming the NFT. Eligible USDC goes to the current owner on the NFT's recorded network once it reaches $0.01. Usage-credit rewards raise that owner's credits with no minimum.

Where we are today

Since this post was published, Testril has reached 0.17.2 and the published CLI now connects to https://api.testril.si/mcp by default. Payment offers remain request- and deployment-specific. Read the connected server's accepts rows instead of inferring a network, asset, or receiver from this illustration. Prices are early and may change.

Closing

For an agent, the whole loop is three steps: see the price, pay exactly that, get the data. x402 provides the payment handshake, and Testril adds per-block pricing, refunds for the unspent part of a stopped materialize job, and an NFT that pays you when your cached data gets used. If you're building agents that need onchain data, see testril.si.