Skip to content

x402 Protocol

AdRail uses x402 for HTTP-native payments. This enables seamless machine-to-machine transactions.

What is x402?

x402 revives the HTTP 402 "Payment Required" status code:

  1. Client requests a resource
  2. Server responds with 402 + payment requirements
  3. Client pays (USDC on Base)
  4. Client retries with payment proof
  5. Server delivers the resource

AdRail x402 Info

bash
curl https://api.adrail.ai/v1/x402/info
json
{
  "protocol": "x402",
  "version": "1.0",
  "testnet": false,
  "facilitator": "https://api.cdp.coinbase.com/x402/facilitator",
  "network": "eip155:8453",
  "networkName": "Base",
  "asset": "USDC",
  "usdcAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "payTo": "0x..."
}

Automatic Payments

Use the x402 client SDK for automatic payment handling:

typescript
import { wrapFetchWithPayment, x402Client } from '@x402/fetch';
import { registerExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';

const signer = privateKeyToAccount(process.env.PRIVATE_KEY);
const client = new x402Client();
registerExactEvmScheme(client, { signer });

const fetch402 = wrapFetchWithPayment(fetch, client);

// Requests automatically pay when 402 is returned
const response = await fetch402('https://api.adrail.ai/v1/paid-endpoint');

Escrow Funding via x402

When funding an escrow, you can use x402 for a seamless flow:

typescript
// Create escrow
const escrow = await fetch('https://api.adrail.ai/v1/escrows', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer ak_xxx' },
  body: JSON.stringify({ amount_usdc: 100 })
}).then(r => r.json());

// Pay to escrow address using x402
await sendUsdc(escrow.payment_address, 100);

// Confirm funding
await fetch(`https://api.adrail.ai/v1/escrows/${escrow.id}/fund`, {
  method: 'POST',
  headers: { 'Authorization': 'Bearer ak_xxx' },
  body: JSON.stringify({ tx_hash: txHash })
});

Resources

Built with x402 • USDC on Base