DEV Community

Praveen Samala
Praveen Samala

Posted on

How I Built a Crypto Data API That AI Agents Pay For (x402 + Express.js

What I Built

A crypto data enrichment API where AI agents pay USDC micropayments per request on Base mainnet.

The Problem

Traditional APIs need subscriptions, API keys, billing systems. AI agents can't sign up for accounts autonomously.

The Solution

x402 protocol — agents discover my API, pay $0.01-$0.10 USDC per request, get data instantly. No signup, no API keys.

Three Endpoints

  • /api/v1/price/{symbol} → $0.01 — real-time price data
  • /api/v1/signal/{symbol} → $0.05 — BUY/HOLD/SELL trading signal
  • /api/v1/deep-analysis/{symbol} → $0.10 — full analysis with risk assessment

Tech Stack

  • Express.js + @x402/express
  • @coinbase/x402 for CDP facilitator auth
  • USDC on Base (eip155:8453)
  • Deployed on Railway ($5/month)

How It Works

  1. Agent requests data
  2. Server returns HTTP 402 with payment instructions
  3. Agent signs USDC transfer, retries with payment proof
  4. Server verifies via CDP facilitator, returns data
  5. USDC lands in my wallet

Try It

API: https://crypto-enrich.up.railway.app
MCP config: https://crypto-enrich.up.railway.app/.well-known/mcp.json

Cost to Build

$5/month hosting. That's it. 88-90% profit margins.

Top comments (0)