I built a DeFi/crypto data API that uses the x402 protocol (by Coinbase) to handle payment natively in the HTTP layer. No API keys, no subscriptions, no accounts. An agent sends a request, gets back a 402 with payment details, pays in USDC on Base, and retries — all in one flow.
How it works:
1. Client calls an endpoint 2. Server returns 402 with payment instructions (x402) 3. Client signs a USDC payment (0.001–0.008 USDC per call) and retries with a payment proof header 4. Server verifies payment and returns the data
The x402 facilitator (middleware) handles verification, so the server just defines prices and serves data.
8 endpoints currently live: token prices, gas tracker, DEX swap quotes, token security scanner, whale tracker, DeFi yield scanner, funding rates, and wallet profiler. Each call costs fractions of a cent (1,000 lookups/day is roughly $1–5).
Built with Express.js. The server is registered as ERC-8004 Agent #18763 on Base mainnet. The whole thing is ~500 lines of code — most of the complexity lives in the x402 facilitator library.
Live: https://x402-api.fly.dev (https://x402-api.fly.dev/) Code: https://github.com/fernsugi/x402-api-server Writeup: https://dev.to/fernsugi/i-built-a-defi-data-api-where-ai-age...