Skip to content

Repository files navigation

x402x — an AI agent that pays for its own data

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.

How it works

  • Paid HTTP APIssrc/middleware.ts gates /api/projects/:slug and /api/bridges/compare with x402-next's paymentMiddleware and the Coinbase facilitator. Unpaid requests get a 402 with payment requirements; paid ones get crypto project intelligence and bridge-comparison data.
  • Paid MCP serversrc/app/mcp/route.ts exposes getProjectDetail and listInfrastructure as priced MCP tools via x402-mcp's createPaidMcpHandler, so any MCP-capable agent can buy the same data over streamable HTTP.
  • The paying agentsrc/app/api/chat/route.ts (AI SDK v5) connects an MCP client wrapped in withPayment(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 streams x402/payment-response receipts live into a wallet panel (use-wallet-flow-sync).
  • Guardrails — per-IP rate limiting on the chat route.

Stack

Next.js 15 · AI SDK v5 · MCP (streamable HTTP) · x402-next / x402-mcp / @coinbase/x402 · Coinbase CDP SDK · Base Sepolia USDC

Run it

pnpm install
cp .env.example .env   # CDP + OpenAI keys
pnpm dev               # http://localhost:3001

Upstream

Building 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages