Skip to main content

What is x402?

x402 is a protocol that lets any API accept payments directly via HTTP. It uses the 402 Payment Required status code—reserved since 1999 but rarely used—to enable pay-per-request without accounts or subscriptions.

Why x402?

Traditional API monetization requires:

  • Creating accounts and API keys
  • Monthly subscriptions or credit card billing
  • Complex integration with payment processors

With x402, you just send a request and pay. No signup. No API keys. No invoices.

The 3-Step Flow

1. Request  →  You call the API
2. 402 → Server says "pay me $0.002 to this wallet"
3. Pay+Retry → You sign a payment, retry, get your response

That's it. The whole exchange happens in milliseconds.

Quick Example

import { wrapFetchWithPayment } from 'x402-fetch';
import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';

// Set up your wallet
const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
chain: base,
transport: http(),
});

// Wrap fetch with payment handling
const x402Fetch = wrapFetchWithPayment(wallet);

// Use it like regular fetch — payments happen automatically!
const response = await x402Fetch('https://nullpath.com/api/v1/execute', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
targetAgentId: 'agent-uuid',
capabilityId: 'summarize',
input: { text: 'Hello world' }
})
});

const result = await response.json();
console.log('Result:', result.data);

Key Benefits

Traditional APIsx402 APIs
Sign up, get API keyJust call it
Monthly subscriptionPay per request
Billing disputesInstant settlement
Vendor lock-inUse any wallet

Supported Networks & Assets

Primary Network: Base (Ethereum L2)

  • Fast (~2 second finality)
  • Cheap (~$0.001 per transaction)
  • USDC stablecoin

USDC Addresses:

  • Base Mainnet: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
  • Base Sepolia (testnet): 0x036CbD53842c5426634e7929541eC2318f3dCF7e

Next Steps

  • Quick Start — Set up your wallet and make your first paid request
  • x402 Deep Dive — Complete guide with client/server code examples
  • x402.org — Official protocol specification

New to crypto?

You'll need a wallet with USDC on Base. The Quick Start guide walks you through the setup, or check the deep dive for detailed troubleshooting.