Skip to content

Payments

x402 uses an on-chain payment → credit model. Consumers make blockchain payments, receive credits, and spend those credits per RPC request.


How It Works

StepAction
1Platform defines pricing plans (payment asset → credit amount)
2Consumer selects a plan and makes an on-chain payment
3Gateway verifies the transaction on-chain
4Credits are issued to the consumer's wallet
5Each RPC call deducts credits before execution
6Requests with zero credits receive 402 Payment Required

Listing Pricing Plans

Retrieve available plans from the gateway:

http
GET /pricing
Authorization: Bearer <your-token>

Response:

json
{
  "plans": [
    {
      "id": "plan_starter",
      "name": "Starter",
      "asset": "USDC",
      "chain": "ethereum",
      "amount": "10.00",
      "credits": 10000,
      "price_per_credit": "0.001"
    },
    {
      "id": "plan_pro",
      "name": "Pro",
      "asset": "USDC",
      "chain": "ethereum",
      "amount": "50.00",
      "credits": 60000,
      "price_per_credit": "0.00083"
    }
  ]
}

Initiating a Payment

Select a plan and get payment details:

http
POST /payments/initiate
Authorization: Bearer <your-token>
Content-Type: application/json

{
  "plan_id": "plan_starter",
  "wallet_address": "0xYourAddress"
}

Response:

json
{
  "payment_id": "pay_abc123",
  "recipient": "0xGatewayTreasuryAddress",
  "asset": "USDC",
  "amount": "10.00",
  "chain_id": 1,
  "expires_at": "2024-06-01T12:15:00Z"
}

Make the on-chain transfer to the recipient address using your wallet.


Confirming a Payment

After broadcasting the transaction, submit the tx hash:

http
POST /payments/confirm
Authorization: Bearer <your-token>
Content-Type: application/json

{
  "payment_id": "pay_abc123",
  "tx_hash": "0x9f3a..."
}

The gateway verifies the transaction on-chain. Once confirmed:

json
{
  "status": "confirmed",
  "credits_issued": 10000,
  "new_balance": 10000
}

Checking Credit Balance

http
GET /credits/balance
Authorization: Bearer <your-token>
json
{
  "address": "0xYourAddress",
  "credits": 9750,
  "last_updated": "2024-06-01T12:30:00Z"
}

Credit Consumption

Credits are deducted before each RPC request is executed. Deduction amounts depend on the method type:

Method TypeExample MethodsCredits
Standard readseth_call, eth_blockNumber, eth_getBalance1
Historical querieseth_getLogs, eth_getStorageAt5
Write methodseth_sendRawTransaction10

INFO

Batch requests consume credits for each individual method call included in the batch.


402 Payment Required

When credits are exhausted, the gateway returns:

http
HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "error": "INSUFFICIENT_CREDITS",
  "message": "Your credit balance is 0. Top up to continue.",
  "credits_required": 1,
  "credits_available": 0,
  "payment_url": "/pricing"
}

This response is machine-readable — autonomous agents and application code can detect it and initiate a top-up automatically.


Payment History

View your payment and credit transaction history:

http
GET /payments/history
Authorization: Bearer <your-token>
json
{
  "payments": [
    {
      "id": "pay_abc123",
      "plan": "Starter",
      "amount": "10.00 USDC",
      "credits": 10000,
      "status": "confirmed",
      "created_at": "2024-06-01T12:00:00Z"
    }
  ]
}

Plan Comparison

PlanAssetAmountCreditsCost per Credit
StarterUSDC$10.0010,000$0.001
ProUSDC$50.0060,000$0.00083
EnterpriseCustomCustomCustomNegotiated

Built on open standards — JSON-RPC 2.0, HTTP 402, SIWx.