HTTP 402 Protocol

Native Payments
for the Internet

x402 enables seamless machine-to-machine payments using the HTTP 402 status code. Built for AI agents, APIs, and the autonomous economy.

< 1s
Transaction Time
$0.001
Minimum Payment
100%
Open Source
terminal
$ npm install @wazabiai/x402
# Client usage
import
{ X402Client } from '@wazabiai/x402/client';
const client = new X402Client({
privateKey: process.env.PRIVATE_KEY
})
// 402 responses handled automatically ✨
const response = await client.fetch(
'https://api.example.com/premium'
);
Core Features

Built for the Agent Economy

Everything you need for seamless machine-to-machine payments

Automatic Payment Flow

The client SDK intercepts 402 responses, signs EIP-712 payloads, and retries requests automatically. Zero manual intervention required.

Auto-retryEIP-712Seamless

Cryptographic Security

Payments are signed with EIP-712 typed data, ensuring tamper-proof transactions verified on-chain.

BNB Smart Chain

Native support for BSC with USDT, USDC, BUSD, and WBNB tokens. More chains coming soon.

Express Middleware

Drop-in middleware for Node.js servers. Protect any route with payment requirements in one line.

TypeScript Native

Full type safety with exported interfaces, Zod validation schemas, and intelligent autocomplete.

Tree-Shakeable

Separate entry points for client and server. Import only what you need to minimize bundle size.

Protocol Flow

How x402 Works

Simple HTTP-based payment flow using the 402 status code

01

Request Resource

Client makes HTTP request to a paid API endpoint

GET /api/premium-data HTTP/1.1
Host: api.example.com
02

402 Response

Server returns 402 with payment details

HTTP/1.1 402 Payment Required
X-Payment-Address: 0x...
X-Payment-Amount: 0.001 USDC
03

Sign & Pay

Client signs transaction and includes payment proof

GET /api/premium-data HTTP/1.1
X-Payment-Signature: 0x...
X-Payment-TxHash: 0x...
04

Access Granted

Server verifies payment and returns the resource

HTTP/1.1 200 OK
Content-Type: application/json

{ "data": "..." }
Live Demo

Live Demo

See the x402 protocol in action. Toggle between client and server implementations.

client.ts
import { X402Client } from '@wazabiai/x402/client';
// Initialize client with your private key
const client = new X402Client({
privateKey: process.env.PRIVATE_KEY,
// Optional callbacks for payment events
onPaymentRequired: (requirement) => {
console.log('Payment needed:', requirement.amount);
},
onPaymentSigned: (payment) => {
console.log('Signed by:', payment.signer);
}
});
// Make requests - 402s are handled automatically!
const response = await client.fetch(
'https://api.example.com/premium-data'
);
console.log(response.data); // Premium content ✨
// HTTP verb shortcuts
await client.get('/api/resource');
await client.post('/api/resource', { data: 'value' });
await client.put('/api/resource', { update: true });
await client.delete('/api/resource');
Quick Start

Start building in 60 seconds

Install the SDK and start accepting payments on your API immediately.

1
npm install @wazabiai/x402 viem
2
import { X402Client } from '@wazabiai/x402/client'
3
const client = new X402Client({ privateKey })
Ecosystem

Supported Tokens

Accept payments in popular stablecoins and native tokens on BNB Smart Chain.

USDT

Tether USD

0x55d3...7955

USDC

USD Coin

0x8AC7...580d

BUSD

Binance USD

0xe9e7...7D56

WBNB

Wrapped BNB

0xbb4C...095c

Ready to monetize your API?

Join the future of programmable payments. Start accepting crypto in minutes.