End-to-end demo of agentic commerce: a chat agent that buys the data it needs, per call, in USDC on Base Sepolia — no API keys, no subscriptions, no human at the checkout. When a tool call comes back 402 Payment Required, the agent pays from its own wallet and retries.
Built in public; earned a $1,000 builder grant within 24 hours of the demo — full story.
- Paid HTTP APIs —
src/middleware.tsgates/api/projects/:slugand/api/bridges/comparewithx402-next'spaymentMiddlewareand the Coinbase facilitator. Unpaid requests get a 402 with payment requirements; paid ones get crypto project intelligence and bridge-comparison data. - Paid MCP server —
src/app/mcp/route.tsexposesgetProjectDetailandlistInfrastructureas priced MCP tools viax402-mcp'screatePaidMcpHandler, so any MCP-capable agent can buy the same data over streamable HTTP. - The paying agent —
src/app/api/chat/route.ts(AI SDK v5) connects an MCP client wrapped inwithPayment(purchaserAccount): the model calls tools normally, and payment settlement happens underneath it. - Wallets — seller and purchaser accounts are provisioned with the Coinbase CDP SDK (
src/lib/wallet.ts); the UI streamsx402/payment-responsereceipts live into a wallet panel (use-wallet-flow-sync). - Guardrails — per-IP rate limiting on the chat route.
Next.js 15 · AI SDK v5 · MCP (streamable HTTP) · x402-next / x402-mcp / @coinbase/x402 · Coinbase CDP SDK · Base Sepolia USDC
pnpm install
cp .env.example .env # CDP + OpenAI keys
pnpm dev # http://localhost:3001Building this surfaced a race in x402-mcp's payment verification (tools failing after successful payment authorization) — reported as x402-mcp#4 with a retry-mechanism fix in x402-mcp#5.