x402 from zero

Lesson 1 is saved.

The status code that waited

Charged$0.00

Make a free account to keep going. Next, you play the program and buy a rainfall reading for $0.001.

Tick any you’d like. All start off.

No password and no card. We use your email to sign you in and for the choices you tick. Your lesson 1 progress moves to your account.

Not now

One payment, step by step

7 minutes. Checked 14 October.

In this lesson

  • The program asks, gets a 402 with the price, signs a payment and sends the same request again.
  • A checker, called a facilitator, verifies the payment and moves the money, so the seller runs no blockchain software.
  • Money moves only at the end, once the data is ready. If the server fails, the program pays nothing.
  • The signature fixes the amount and who gets paid, works once and soon expires.
Go through it step by step

A farmer sells rainfall

In this lesson you play a program buying one rainfall reading, and see exactly when the money moves.

A farmer logs rainfall every hour and sells each reading for $0.001. A weather program planning irrigation for another farm needs the latest one. It has never visited the farmer’s site, has no account there and holds no API key.

Who takes part

Every x402 payment has the same four parties.

  • You, the client: here, the weather program. You ask for the reading and pay.
  • The site, or resource server: the farmer’s server. It sets the price and serves the reading. A paid tool that an AI assistant calls over MCP can play this part too, and is paid the same way.
  • The checker: a service the site uses to check payments and move the money, so the farmer runs no blockchain software. Its real name is the facilitator. Coinbase runs the one that handles most payments on Base.
  • Base: the network where the USDC actually moves.

Buy one reading yourself

You’re the weather program, with a small USDC budget.

Money moved so far$0.000
  1. You ask for the reading

    The agent asks for the latest rainfall reading near a farm. It sends an ordinary request, with no payment and no API key.

    Show the real messageHide the real message
    GET /v1/rainfall?lat=52.62&lon=1.29 HTTP/1.1
    Host: rain.example.com
    Accept: application/json

    Header names and message shapes follow the x402 v2 spec. Long lines are cut short. The seller, wallets, signature and transaction hash are made-up examples; the USDC contract address and the Base network ID are real.

  2. The site answers 402, with the price

    The server answers 402 Payment Required. The PAYMENT-REQUIRED header carries the price in base64, and the body shows the same details in plain JSON: 1,000 units of USDC (USDC counts in millionths of a dollar, so that is $0.001) on Base, paid to the seller’s wallet.

    Show the real messageHide the real message
    HTTP/1.1 402 Payment Required
    Content-Type: application/json
    PAYMENT-REQUIRED: eyJ4NDAyVmVyc2lvbiI6MiwiZXJyb3IiOiJQQVlNRU5ULVNJR05BVFVSRSBoZWFkZXIgaXMgcmVxdWlyZWQiLCJyZXNvdXJjZSI6eyJ1cmwiOiJodHRwczovL3JhaW4uZXhhbXBsZS5jb20vdjEvcmFpbmZhbGw/bGF0PTUyLjYyJmxvbj0xLjI5IiwiZGVzY3JpcHRpb24iOiJMYXRlc3QgcmFpbmZhbGwgcmVhZGluZzogbWlsbGltZXRyZXMgaW4gdGhlIGxhc3QgaG91ciIsIm1pbWVUeXBlIjoiYXBwbGljYXRpb24vanNvbiJ9LCJhY2NlcHRzIjpbeyJzY2hlbWUiOiJleGFjdCIsIm5ldHdvcmsiOiJlaXAxNTU6ODQ1MyIsImFtb3VudCI6IjEwMDAiLCJhc3NldCI6IjB4ODMzNTg5ZkNENmVEYjZFMDhmNGM3QzMyRDRmNzFiNTRiZEEwMjkxMyIsInBheVRvIjoiMHgyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyIiwibWF4VGltZW91dFNlY29uZHMiOjYwLCJleHRyYSI6eyJuYW1lIjoiVVNEIENvaW4iLCJ2ZXJzaW9uIjoiMiJ9fV19
    
    {
      "x402Version": 2,
      "error": "PAYMENT-SIGNATURE header is required",
      "resource": {
        "url": "https://rain.example.com/v1/rainfall?lat=52.62&lon=1.29",
        "description": "Latest rainfall reading: millimetres in the last hour",
        "mimeType": "application/json"
      },
      "accepts": [
        {
          "scheme": "exact",
          "network": "eip155:8453",
          "amount": "1000",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x2222222222222222222222222222222222222222",
          "maxTimeoutSeconds": 60,
          "extra": {
            "name": "USD Coin",
            "version": "2"
          }
        }
      ]
    }

    Header names and message shapes follow the x402 v2 spec. Long lines are cut short. The seller, wallets, signature and transaction hash are made-up examples; the USDC contract address and the Base network ID are real.

  3. You check your budget

    Before signing anything, the agent’s payment software checks the offer against the limits its owner set: which networks and tokens it may use, and how much it may pay per request. The x402 reference client refuses any single payment over $1 unless the owner raises that cap. $0.001 is well inside it.

  4. You sign the payment

    The agent signs a message with its wallet’s private key: move exactly 1,000 units of USDC from my wallet to the seller’s, valid for the next 60 seconds, with a one-time random number so it can never be reused. Signing moves no money. It is a permission slip only the agent’s key can write.

  5. You ask again, with the payment

    The agent repeats the same request. This time it adds a PAYMENT-SIGNATURE header holding the signed permission slip, packed as base64.

    Show the real messageHide the real message
    GET /v1/rainfall?lat=52.62&lon=1.29 HTTP/1.1
    Host: rain.example.com
    Accept: application/json
    PAYMENT-SIGNATURE: eyJ4NDAyVmVyc2lvbiI6MiwicmVzb3VyY2UiOnsidXJsIjoiaHR0cHM6Ly9yYWluLmV4YW1wbGUuY29tL3YxL3JhaW5mYWxsP2xhdD01Mi42MiZsb249MS4yOSJ9LCJhY2NlcHRlZCI6eyJzY2hlbWUiOiJleGFjdCIsIm5ldHdvcmsiOiJlaXAxNTU6ODQ1MyIsImFtb3VudCI6IjEwMDAiLCJhc3NldCI6IjB4ODMzNTg5ZkNENmVEYjZFMDhmNGM3QzMyRDRmNzFiNTRiZEEwMjkxMyIsInBheVRvIjoiMHgyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyIiwibWF4VGltZW91dFNlY29uZHMiOjYwLCJleHRyYSI6eyJuYW1lIjoiVVNEIENvaW4iLCJ2ZXJzaW9uIjoiMiJ9fSwicGF5bG9hZCI6eyJzaWduYXR1cmUiOiIweDVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWU1ZTVlNWUiLCJhdXRob3JpemF0aW9uIjp7ImZyb20iOiIweDExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEiLCJ0byI6IjB4MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMiIsInZhbHVlIjoiMTAwMCIsInZhbGlkQWZ0ZXIiOiIwIiwidmFsaWRCZWZvcmUiOiIxNzkxOTc3NDYwIiwibm9uY2UiOiIweGFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWJhYmFiYWIifX19

    Header names and message shapes follow the x402 v2 spec. Long lines are cut short. The seller, wallets, signature and transaction hash are made-up examples; the USDC contract address and the Base network ID are real.

  6. The checker verifies

    The seller’s server passes the payment to a facilitator, here Coinbase’s. The facilitator checks the signature, the amount, the recipient, the time window and the agent’s USDC balance. Checking costs nothing and moves nothing. Once it says the payment is valid, the server looks up the reading.

    Show the real messageHide the real message
    POST /platform/v2/x402/verify HTTP/1.1
    Host: api.cdp.coinbase.com
    Authorization: Bearer …
    Content-Type: application/json
    
    {
      "x402Version": 2,
      "paymentPayload": { "x402Version": 2, "accepted": { … }, "payload": { "signature": "0x5e5e…", "authorization": { … } } },
      "paymentRequirements": { "scheme": "exact", "network": "eip155:8453", "amount": "1000", … }
    }

    The checker answers:

    HTTP/1.1 200 OK
    Content-Type: application/json
    
    {"isValid": true, "payer": "0x1111111111111111111111111111111111111111"}

    Header names and message shapes follow the x402 v2 spec. Long lines are cut short. The seller, wallets, signature and transaction hash are made-up examples; the USDC contract address and the Base network ID are real.

  7. The checker settles

    With the reading ready, the server asks the facilitator to settle. The facilitator submits the signed authorization to Base and reports back with the transaction hash, the public ID of the transfer.

    Show the real messageHide the real message
    POST /platform/v2/x402/settle HTTP/1.1
    Host: api.cdp.coinbase.com
    Authorization: Bearer …
    Content-Type: application/json
    
    {
      "x402Version": 2,
      "paymentPayload": { "x402Version": 2, "accepted": { … }, "payload": { "signature": "0x5e5e…", "authorization": { … } } },
      "paymentRequirements": { "scheme": "exact", "network": "eip155:8453", "amount": "1000", … }
    }

    The checker answers:

    HTTP/1.1 200 OK
    Content-Type: application/json
    
    {"success": true, "payer": "0x1111111111111111111111111111111111111111", "transaction": "0x7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a", "network": "eip155:8453"}

    Header names and message shapes follow the x402 v2 spec. Long lines are cut short. The seller, wallets, signature and transaction hash are made-up examples; the USDC contract address and the Base network ID are real.

  8. USDC moves on Base

    On Base, the USDC contract checks the signature and moves 0.001 USDC from the agent’s wallet to the seller’s. The facilitator pays the small network fee, called gas, so the agent needs no other token. The one-time number is now used up, so the same signature can never pay twice.

  9. The reading comes back, with a receipt

    The server sends the reading with 200 OK. The PAYMENT-RESPONSE header is the receipt: decoded, it says the payment succeeded and gives the transaction hash, which anyone can look up on a Base block explorer.

    Show the real messageHide the real message
    HTTP/1.1 200 OK
    Content-Type: application/json
    PAYMENT-RESPONSE: eyJzdWNjZXNzIjp0cnVlLCJ0cmFuc2FjdGlvbiI6IjB4N2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YTdhN2E3YSIsIm5ldHdvcmsiOiJlaXAxNTU6ODQ1MyIsInBheWVyIjoiMHgxMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExIn0=
    
    {
      "lat": 52.62,
      "lon": 1.29,
      "rainfall_mm_last_hour": 0.4,
      "observed_at": "2026-10-14T11:00:00Z"
    }

    Header names and message shapes follow the x402 v2 spec. Long lines are cut short. The seller, wallets, signature and transaction hash are made-up examples; the USDC contract address and the Base network ID are real.

One rainfall reading

rain.example.com

You ask for the reading$0.000
The site answers with a price$0.000
You check your budget$0.000
You sign the payment$0.000
You ask again, signed$0.000
The checker verifies it$0.000
The checker settles it$0.000
USDC moves on Base$0.001
The reading comes back$0.000

Money moved once. Charged to you: $0.001.

When does the money actually move?

Your choice is checked as soon as you pick it. With a keyboard, move with the arrow keys and press Space to choose.

Right.

Not quite.

Signing and checking move nothing. In the default flow the checker settles only once the site has the reading ready, so if the site fails first, you pay nothing. Some other schemes settle before the work is done.

What your signature protects

Your signed payment works like a cheque with four rules written in. It uses EIP-3009, a USDC feature that lets someone else submit a transfer you signed.

  • The amount and who gets paid are fixed. Change either and the signature stops matching, so not even the checker can.
  • It expires, here after 60 seconds.

What your signature protects

  • It works once. A one-time number is used up at settlement, when the money moves.
  • No account is needed. The site sees a wallet address and a signature, never a card or a key.

Careful. x402 doesn’t judge the reading. If the farmer’s number is wrong, there’s no refund button. Any fix is up to the seller.

The seller’s side of the bill

The farmer earns $0.001 a reading. Coinbase’s checker charges sellers nothing for the first 1,000 settlements each month and $0.001 for each one after that (14 Oct) source. Past the free tier, the fee is as large as the whole sale.

For prices this small, x402 also has a batch-settlement scheme, merged in April 2026, where many signed payments share one claim on the chain. Coinbase’s isn’t the only checker, and the build track compares them.

One question this leaves open: you paid from your own wallet, so where did that USDC come from? That’s the next lesson.

When your USDC moves on Base, who pays the network fee?

Your choice is checked as soon as you pick it. With a keyboard, move with the arrow keys and press Space to choose.

Right.

Not quite.

The x402 spec for this kind of payment says the facilitator, your checker, pays the network fee, called gas. You only sign.

Lesson done.

Price: about 7 minutes of your attention.

You can now say

  • The program asks, gets a 402 with the price, signs a payment and sends the same request again.
  • A checker, called a facilitator, verifies the payment and moves the money, so the seller runs no blockchain software.
  • Money moves only at the end, once the data is ready. If the server fails, the program pays nothing.
  • The signature fixes the amount and who gets paid, works once and soon expires.

Sources

Checked 14 October

  1. x402 Protocol Specification, version 2 (core flow, facilitator /verify and /settle, payment flows) github.com
  2. x402 v2 HTTP transport: PAYMENT-REQUIRED, PAYMENT-SIGNATURE, PAYMENT-RESPONSE github.com
  3. x402 v2 MCP transport: paying for tools github.com
  4. Scheme exact: authorization flow leaves the client uncharged if the handler fails github.com
  5. Scheme exact on EVM: EIP-3009, facilitator pays gas, cannot change amount or destination github.com
  6. ERC-3009: Transfer With Authorization eips.ethereum.org
  7. x402 reference SDK: client signs with validBefore = now + maxTimeoutSeconds github.com
  8. x402 core README: client spend controls, $1 default cap per payment github.com
  9. x402 seller quickstart: testnet facilitator and Coinbase’s mainnet facilitator URL github.com
  10. Coinbase CDP docs: facilitator pricing, free verification, screening docs.cdp.coinbase.com
  11. x402scan: Base settlements by facilitator (Coinbase 91% of Base transactions, 2026-04-11 to 2026-10-11) x402scan.com
  12. x402 PR 1145: batch-settlement scheme, merged 15 April 2026 github.com
  13. Base docs: built by Coinbase; transactions settle in under a second and cost less than one cent (Base’s claim) docs.base.org