x402 Service Provider Guide

How to accept x402 payments for your API or service on the Azeth platform.


Overview

x402 lets you monetize any HTTP endpoint. When a client requests a paid resource, your server returns HTTP 402 with payment terms. The client pays on-chain and retries with proof. Your server validates and delivers the response.

Azeth supports four access methods:

  1. x402 Payment — one-time payment per request (EOA signs ERC-3009)
  2. Smart Account Payment — one-time payment routed through a smart account (guardian guardrails enforced)
  3. SIWx Session — wallet signature proves prior payment (no additional payment needed)
  4. Payment Agreement — on-chain subscription grants ongoing access

Setup

Dependencies

pnpm add @x402/core @x402/hono @x402/evm @x402/extensions

Route Configuration

Declare which endpoints require payment:

const routes = {
  'GET /api/v1/pricing/[coinId]': {
    accepts: {
      scheme: 'exact',
      price: '$0.01',
      network: 'eip155:84532',
      payTo: '0xYourAddress...',
    },
    description: 'Real-time cryptocurrency price data',
    mimeType: 'application/json',
  },
};

Hono Middleware

import { paymentMiddlewareFromHTTPServer } from '@x402/hono';

app.use('*', paymentMiddlewareFromHTTPServer(httpServer));

Environment Variables

VariableRequiredDescription
X402_PAY_TOYesAddress that receives USDC payments
X402_FACILITATOR_KEYYesPrivate key for settlement
X402_PRICE_FEED_PRICENoUSD price per request (default: $0.01)

When X402_PAY_TO is not set, paid endpoints return 503 (graceful degradation).


Payment Agreements (Subscriptions)

You can advertise subscription terms in your 402 response. Clients create an on-chain payment agreement matching your terms, then access your service without per-request payments.

{
  "extensions": {
    "payment-agreement": {
      "acceptsAgreements": true,
      "terms": {
        "payee": "0x...",
        "token": "0x036C...",
        "minAmountPerInterval": "10000",
        "suggestedInterval": 86400
      }
    }
  }
}

Clients can subscribe using the azeth_subscribe_service MCP tool or the SDK's createPaymentAgreement() method.


Security

  • Self-hosted facilitator — you control settlement, no external dependency
  • ERC-3009 settlement — nonce dedup and timing validation handled by @x402/evm
  • SIWx signatures verified cryptographically (ECDSA + EIP-1271 for smart wallets)
  • Agreement validation is always on-chain — no trust assumptions
  • Smart account payments enforce guardian guardrails on-chain

See Also