# Introduction
Turn any API into a paid service โ No registration, no API Key, AI Agents pay and consume autonomously.
## What is ZAN x402?
ZAN x402 is an AI Agent payment gateway platform launched by ZAN, built on the x402 protocol โ an open payment standard initiated by Coinbase. It enables any API to easily implement paid access, where AI Agents can use wallet identity and on-chain USDC for autonomous payments.
### Core Value
| Feature | Description |
| ------------------------------- | ------------------------------------------------------------------------------------------ |
| ๐ฏ **No Registration Required** | Wallet as identity โ start with just one signature |
| ๐ **On-Chain Settlement** | Transparent, verifiable USDC settlement on Base and Solana |
| ๐ค **Agent-Native** | Designed for AI Agents with single-session primitives and machine-parseable 402 challenges |
| ๐ณ **Credit System** | Purchase once, use anywhere โ one balance across the entire platform |
| ๐ **Multi-Chain RPC** | Supports 30+ networks: ETH, Solana, Bitcoin, Base, Arbitrum, and more |
***
## Why Choose ZAN x402?
### 1. Traditional API Payments vs ZAN x402
| Comparison | Traditional API Payments | ZAN x402 |
| ---------------------- | ------------------------------------------- | ----------------------------------------------- |
| Integration | Register account, apply for API Key, top up | Connect wallet, purchase credits, call directly |
| Payment Method | Prepaid/postpaid cycle settlement | Real-time on-chain USDC settlement |
| Agent Support | Requires human intervention | Agent autonomous payment, no human needed |
| Multi-provider Billing | Need separate integration | Unified balance, one top-up for entire platform |
### 2. Built for the Agent Economy
In the AI Agent era, services need to be autonomously discovered, verified, and paid for by machines. ZAN x402 provides:
* **Wallet Identity Authentication**: EVM (MetaMask) and SVM (Phantom) wallet signatures replace traditional account registration
* **Transparent Payments**: On-chain USDC settlement, every transaction verifiable
* **Discovery-First**: Automatically detect available networks and bundles at startup, seamless integration with dynamic tool catalogs
### 3. Industry Trend
The x402 protocol was launched by Coinbase in May 2025 and is becoming the standard for AI Agent payments:
* Coinbase x402 Protocol โ Open payment protocol enabling AI Agents to make autonomous stablecoin micropayments
* Galaxy Research โ x402 makes AI Agents economic actors
* Zuplo MCP Payments โ AI Agents autonomously pay for APIs and MCP Servers
***
## Core Features
### ๐ Wallet Identity Authentication
* **EVM Wallets**: MetaMask and other wallet signatures (SIWE)
* **SVM Wallets**: Phantom and other wallet signatures (SIWS)
* Automatic JWT session acquisition with auto-refresh support
### ๐ณ USDC On-Chain Payment
* **Settlement Currency**: USDC
* **Supported Chains**: Base, Solana
* **Transparent & Verifiable**: Every transaction traceable on-chain
### ๐ Credit System
* Purchase once, use anywhere
* Unified balance management
* Real-time usage tracking
### ๐ Multi-Chain RPC Service
| Category | Supported Networks |
| -------- | --------------------------------------------------------------------------- |
| EVM | Ethereum, Base, Arbitrum, Optimism, Polygon, Avalanche, BNB Chain, and more |
| SVM | Solana |
| Others | Bitcoin and more |
### ๐ Real-time Monitoring
* Track every call and credit change in real-time
* Detailed usage records available
***
## How It Works
```
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Client โ โ Gateway โ โ Facilitator โ
โ (AI Agent) โ โ (ZAN x402) โ โ (On-Chain) โ
โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ
โ โ โ
โโโ POST /rpc โโโโโ>โ โ
โ<โโ 402 โโโโโโโโโโโโ โ
โ โ โ
โโโ POST /purchase โโโโโโโโโโโโโโโโโโโโ>โ
โ<โโ 402 + PAYMENT-REQUIRED โโโโโโโโโโโโโ
โ [Sign EIP-3009 / Solana SPL] โ
โ โ โ
โโโ POST /purchase (+signature) โโโโโโโ>โ
โ โโโ POST /verify โโ>โ
โ โ<โโ valid, txHash โโ
โ<โโ 200 + credits โโ โ
โ โ โ
โโโ POST /rpc โโโโโ>โ [Retry] โ
โ<โโ 200 + result โโโ โ
```
**Three Steps to Get Started:**
1. **Connect Wallet**: MetaMask or Phantom, one signature
2. **Purchase Credits**: USDC on-chain, instant settlement
3. **Call APIs**: Credits unlock every API on the platform
***
## Quick Start
```bash
# Install
npm install @zan_team/x402 viem
```
```typescript
import { createX402Client } from '@zan_team/x402';
const client = await createX402Client({
gatewayUrl: 'https://x402.zan.top',
privateKey: process.env.PRIVATE_KEY as `0x${string}`,
autoPayment: true,
preAuth: true,
});
// Call RPC
const block = await client.call('eth', 'mainnet', 'eth_blockNumber');
console.log('Latest block:', block.result);
```
For detailed steps, see the Quickstart Guide
***
## SDK Architecture
```
X402Client
โโโ auth AuthModule SIWE/SIWS + JWT session management
โโโ credits CreditsModule Balance ยท Purchase ยท Usage ยท Payment status
โโโ rpc RpcModule JSON-RPC ยท Batch calls ยท Provider forwarding
โโโ discovery DiscoveryModule Health check ยท Network list ยท Bundle list ยท x402 capability detection
```
### Subpath Exports
```typescript
import { AuthModule } from '@zan_team/x402/auth';
import { CreditsModule } from '@zan_team/x402/credits';
import { RpcModule } from '@zan_team/x402/rpc';
```
***
## Configuration Options
```typescript
interface X402ClientConfig {
gatewayUrl: string; // Gateway URL
// EVM
wallet?: WalletClient; // viem WalletClient
privateKey?: `0x${string}`; // Hex private key
// SVM
svmPrivateKey?: string; // Base58 private key
paymentNetwork?: string; // CAIP-2, e.g. "eip155:8453"
solanaRpcUrl?: string; // Solana RPC URL
// Behavior config
chainType?: 'EVM' | 'SVM'; // Auto-detected
autoPayment?: boolean; // Auto-purchase when credits insufficient
defaultBundle?: BundleType; // Default bundle
preAuth?: boolean; // Pre-authenticate on creation
timeout?: number; // Timeout in ms, default 30000
fetch?: typeof fetch; // Custom fetch implementation
}
```
***
## Error Handling
| Error Type | HTTP Status | Scenario |
| -------------------------- | ----------- | ----------------------------------- |
| `AuthenticationError` | 401 | SIWE/SIWS signature rejected |
| `SessionExpiredError` | 401 | JWT session expired |
| `InsufficientCreditsError` | 402 | Insufficient credits |
| `InsufficientFundsError` | 402 | On-chain USDC balance insufficient |
| `PaymentRejectedError` | 402 | Payment rejected |
| `MethodNotAllowedError` | 403 | Method not allowed for current tier |
| `ProviderNotFoundError` | 404 | No matching provider found |
| `UpstreamError` | 504 | Provider failed |
| `NetworkError` | โ | Network/timeout error |
***
## Project Structure
```
zanx402-sdk/
โโโ src/
โ โโโ index.ts # Public API exports
โ โโโ client.ts # X402Client + createX402Client
โ โโโ constants.ts # Endpoint configuration
โ โโโ types/ # Type definitions
โ โโโ modules/ # Feature modules
โ โ โโโ auth.ts # SIWE/SIWS + JWT
โ โ โโโ credits.ts # Credit management
โ โ โโโ rpc.ts # JSON-RPC
โ โ โโโ discovery.ts # Discovery module
โ โโโ errors/ # Error types
โ โโโ utils/ # Utility functions
โโโ docs/
โ โโโ quickstart.md # Quickstart guide
โโโ tests/ # Unit tests
โโโ package.json
```
***
## Environment Requirements
| Item | Requirement |
| --------------- | ----------------- |
| Node.js | >= 18 |
| Package Manager | npm / pnpm / yarn |
***
## Related Links
* GitHub Repository
* x402 Protocol Website
* ZAN Website
***