
How to Add Pay-Per-Call Crypto Payments to Any API in 5 Minutes (x402 + Base)
Your API returns 200 OK for free. What if it returned 402 Payment Required and got paid in USDC? That's exactly what the HTTP 402 spec was designed for — it's just been unused for 30 years. The x402 protocol finally makes it real, on Base. The Problem You built a useful API. Maybe it's a data enrichment endpoint, an AI inference wrapper, or a niche scraper. You want to monetize it — but: API keys mean user signup flows Stripe means billing integrations and KYC Rate limiting by IP is trivially bypassed What if payment was the authentication? The 3-Line Fix With the x402 middleware , adding pay-per-call to an Express API takes literally 3 lines: import { paymentMiddleware } from " x402-express " ; app . use ( paymentMiddleware ( " 0xYourWalletAddress " , { " /api/data " : { price : " $0.01 " , network : " base " } } )); That's it. When an agent or client hits /api/data , they get back: HTTP 402 Payment Required X-Payment-Requirements: {"price":"0.01","network":"base","token":"USDC"} The
Continue reading on Dev.to JavaScript
Opens in a new tab


