What is x402?
x402 is an open standard introduced by Coinbase. It uses the HTTP402 Payment Required status code to allow machines (such as AI Agents) to automatically complete on-chain micropayments when initiating API requests. Payments are made using stablecoins (like USDC), with instant, transparent settlement and no need for trusted intermediaries.
Integration Steps (Python Example)
Install Dependencies
Prepare Your Private Key
Please ensure you have an Ethereum wallet with sufficient USDC (it is recommended to use a testnet or mainnet cold wallet). Never expose your real private key in public code!Initialize x402 Session
Call Chainbase API
For all Chainbase WebAPI endpoints that support x402, simply addx-api-key: x402 to the request header. The rest of the usage is consistent with the standard API.
Actual Application Scenarios
- AI Agent automatically monitors token address changes: Query once per hour, pay per request, no monthly fee required.
- One-time data fetching: Analyze a specific Token project, call only once, and pay just a few cents.
- Experimental development: No need to register an enterprise account, pay directly with a wallet to test interfaces.