Minimal Node.js starter for AI agents to accept x402 payments on Base
x402-agent-starter is an early-stage JavaScript project in the AI payments / x402 ecosystem. It currently has 0 GitHub stars and 0 forks.
Deploy a paid AI agent endpoint on Base in minutes. Built for autonomous agents that need monetizable infrastructure.
Your agent earns USDC on Base when callers pay via the x402 protocol. No merchant account. No Stripe. No custody. Just a server that speaks the x402 standard.
| Route | Price | What you get |
|---|---|---|
GET /api/data |
$0.01 USDC | Live DeFi yield gap — Aave vs Morpho USDC |
GET /api/wallet |
$0.01 USDC | Base wallet profiler + token balances |
GET /api/token |
$0.01 USDC | ERC20 token metadata + risk signals |
GET /api/tx |
$0.02 USDC | Transaction decoder + event log |
GET /api/history |
$0.05 USDC | Yield history + decay analysis |
All endpoints are x402-payment-gated on Base Mainnet (eip155:8453). Payment goes to your configured PAY_TO_ADDRESS.
The server behind this repo is live at webcams-log-under-general.trycloudflare.com:
# Health check
curl https://your-tunnel-url.trycloudflare.com/health
# Try a paid call (returns 402 with payment instructions)
curl https://your-tunnel-url.trycloudflare.com/api/data
# Pay and call — step by step
# 1. Get 402 response with payment requirements
curl https://your-tunnel-url.trycloudflare.com/api/data
# 2. Pay USDC to 0x4226... via your Base wallet (MetaMask, Rabby, programmatic)
# 3. Retry with your transaction hash
curl -H "x402-response: YOUR_TX_HASH" \
https://your-tunnel-url.trycloudflare.com/api/data
# For production MCP agents: use @x402/mcp for automatic payment lifecycle
git clone https://github.com/forge-builder/x402-agent-starter.git
cd x402-agent-starter
npm install
# Set your payment address (the wallet that receives USDC)
export PAY_TO_ADDRESS=0xYourBaseAddress
export PORT=3000
node server.js
See examples/x402-caller.js — a Node.js script that demonstrates the full x402 payment flow from an AI agent's perspective (discovery → parse → sign → pay → retry). Run it against any x402 endpoint:
PRIVATE_KEY=0x... ENDPOINT_URL=https://your-endpoint.com node examples/x402-caller.js
Without a private key it runs in simulation mode and walks through every step.
See docs/x402-payment-flow.md for the complete technical reference: two-step flow, header specs, payment lifecycle diagrams, and troubleshooting.
eip155:8453)https://mainnet.base.orgyield-history.json for historical datasequenceDiagram
participant Agent as AI Agent
participant MCP as @x402/mcp Client
participant Server as x402 Server
participant Blockchain as Base (USDC)
participant Facilitator as x402 Facilitator
Agent->>MCP: callTool("x402_data")
MCP->>Server: GET /api/data
Server-->>MCP: 402 Payment Required
MCP->>Agent: payment required
Agent->>MCP: approve(payment)
MCP->>Blockchain: sign EIP-712 permit
Blockchain-->>MCP: permit signature
MCP->>Blockchain: submit tx (pay USDC)
Blockchain-->>MCP: tx hash
MCP->>Server: GET /api/data (x402-response: tx_hash)
Server->>Facilitator: settle payment
Server-->>MCP: 200 OK + data
MCP-->>Agent: tool result
Fork it, replace the endpoint logic with your agent's capabilities, and you have a monetizable agent.
Two DEV.do drafts explore the demand side and market context:
content/devto-article-draft.md — Original framing: building a paid x402 endpointcontent/devto-article-draft-V2.md — "AI-to-AI Payments on Base" — leads with the 480K+ Base agent market, ERC-8004 identity, and AI-to-AI payment framingOr use the included LaunchAgent plist for persistent server management on macOS.
x402 is a general payment protocol for any HTTP service. These projects use x402 for real economic activity:
| Project | Description | x402 Role |
|---|---|---|
| afara | IPFS storage pay-as-you-go | Payment rail |
| x402-Solana | Official Solana x402 agent docs | Multi-chain |
| rustyqt/x402-agent | Python AI agent with web3.py | AI agent |
| @x402/mcp | MCP protocol integration (v2.11.0) | AI agents |
| x402-foundation/x402 | Protocol + SDKs (6k stars) | Foundation |
Client SDK, Claude plugin and skill framework for the Pinion protocol. x402 micropayments on Base.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Turn any API or MCP server into a paid service with x402
Public adapters and discovery catalog for Triptych OS (Agent OS): agent frameworks, MCP/A2A/x402 protocols, workflows, wallets, SDKs, and examples for execute-first routing, governed handoffs, and receipt-aware agent commerce.
A wallet for agents. Make payments via x402, use stablecoins, swap assets, earn yield with defi and buy tokenized stocks across the most popular chains.