# 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 ***