Now supporting BNB Smart Chain

Programmable Payments
for the Modern Web

The x402 protocol brings native crypto payments to HTTP. Build pay-per-use APIs, premium content gates, and microtransaction systems with a single TypeScript SDK.

402 HTTP Status
EIP-712 Typed Signatures
BSC Network
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'
);

Everything you need for
Web3 Payments

A complete toolkit for building payment-enabled applications on the blockchain.

Automatic Payment Flow

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

Auto-retry EIP-712 Seamless

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.

How x402 Works

A simple four-step flow that brings payments to any HTTP endpoint.

01

Request

Client makes a standard HTTP request to a protected endpoint.

GET /api/premium
02

402 Response

Server responds with payment requirements in the header.

X-Payment-Required: {...}
03

Sign Payment

Client signs EIP-712 typed data with their private key.

signTypedData({...})
04

Access Granted

Server verifies signature and returns the protected resource.

200 OK { data: ... }

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');
server.ts
import express from 'express';
import { 
  x402Middleware, 
  BSC_USDT,
  parseTokenAmount 
} from '@wazabiai/x402/server';

const app = express();

// Configure payment requirements
const paymentConfig = {
  recipientAddress: '0xYourWalletAddress',
  amount: parseTokenAmount('0.10', BSC_USDT.address).toString(),
  tokenAddress: BSC_USDT.address,
  description: 'Access to premium API',
};

// Protect routes with one line
app.use('/api/premium', x402Middleware(paymentConfig));

// Your protected route
app.get('/api/premium/data', (req, res) => {
  // Payment verified ✓
  const { x402 } = req;
  console.log(`Paid by: ${x402?.signer}`);
  
  res.json({ 
    premium: 'content',
    secret: 'data' 
  });
});

app.listen(3000);
types.ts
import type {
  PaymentRequirement,
  PaymentPayload,
  SignedPayment,
  X402ClientConfig,
  X402MiddlewareConfig,
} from '@wazabiai/x402/types';

// Payment requirement (402 response)
interface PaymentRequirement {
  amount: string;        // Wei amount
  token: string;         // Token address
  network_id: string;    // "eip155:56"
  pay_to: string;        // Recipient
  expires_at?: number;   // Unix timestamp
  nonce?: string;        // Replay protection
}

// EIP-712 payment payload
interface PaymentPayload {
  amount: string;
  token: string;
  chainId: number;
  payTo: string;
  payer: string;
  deadline: number;
  nonce: string;
  resource?: string;
}

// Signed payment for retry
interface SignedPayment {
  payload: PaymentPayload;
  signature: `0x${string}`;
  signer: `0x${string}`;
}

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 })

Supported Tokens

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

USDT

Tether USD

0x55d3...7955
$

USDC

USD Coin

0x8AC7...580d
B

BUSD

Binance USD

0xe9e7...7D56

WBNB

Wrapped BNB

0xbb4C...095c

Resources & Documentation

Everything you need to integrate x402 into your project.

Ready to monetize your API?

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