{"slug": "show-hn-x402-express-pay-per-call-http-402-middleware-for-ai-agents-on-base-l2", "title": "Show HN: X402-express. Pay-per-call HTTP 402 middleware for AI agents on Base L2", "summary": "M2MCent released X402-express, an open-source middleware that enables AI agents to pay per API call using USDC on Base L2. The npm package implements the x402 payment protocol, allowing developers to add a paywall to any Express endpoint with three lines of code, processing atomic on-chain settlements through an escrow contract. The tool is designed for AI-to-AI commerce, with over 100 production Model Context Protocol servers already using the system for real USDC micro-payments.", "body_md": "Ultra-lightweight x402 payment interceptor for AI Agents and MCP Servers. Monetize any API in 3 lines of code.\n\n```\nnpm install m2mcent-sdk\njs\nimport { X402Handler } from 'm2mcent-sdk';\n\nconst x402 = new X402Handler({\n  rpcUrl: 'https://mainnet.base.org',\n  privateKey: process.env.RELAYER_PRIVATE_KEY!,\n  recipient: process.env.TREASURY_ADDRESS!\n});\n\n// Protect any Express endpoint with a USDC paywall\napp.post('/api/analyze', x402.requirePayment(\"100000\"), (req, res) => {\n  res.json({ result: \"Premium analysis complete\", receipt: req.paymentTx });\n});\n```\n\nM2MCent implements the **x402 Payment Protocol** — a machine-native payment standard inspired by HTTP 402:\n\n**Agent requests** a protected endpoint**Server responds** with`402 Payment Required`\n\n+ payment metadata (Base64 encoded)**Agent signs** an EIP-712 typed data authorization (gasless for the payer)**Server settles** atomically on-chain via the M2MCent Escrow contract**Agent receives** the premium response + transaction receipt\n\n```\nAgent ──► API Server ──► 402 + metadata\nAgent ◄── signs EIP-712 authorization\nAgent ──► API Server + Payment-Signature header\n          └──► Escrow.settle() on Base L2\nAgent ◄── Premium Response + tx hash\n```\n\n| Parameter | Description | Required |\n|---|---|---|\n`rpcUrl` |\nBase Mainnet RPC endpoint | ✅ |\n`privateKey` |\nRelayer wallet private key (for settlement) | ✅ |\n`recipient` |\nTreasury address to receive payments | ✅ |\n\n**Non-custodial**: Funds flow directly from payer → treasury via on-chain escrow** Gasless for payers**: Uses EIP-3009`transferWithAuthorization`\n\n(USDC native)**Zero-Leak**: No agent data is retained after settlement** Atomic**: Payment and service delivery happen in a single request cycle\n\n| Parameter | Value |\n|---|---|\nNetwork |\nBase Mainnet (Chain ID: 8453) |\nUSDC Contract |\n`0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |\nEscrow Contract |\n`0xf3c3416A843d13C944554A54Ac274BB7fF264BcC` |\nSettlement |\nAtomic, sub-second finality |\n\nPerfect for [Model Context Protocol](https://modelcontextprotocol.io) servers:\n\n``` python\nimport express from 'express';\nimport { X402Handler } from 'm2mcent-sdk';\n\nconst app = express();\nconst x402 = new X402Handler({\n  rpcUrl: process.env.BASE_RPC_URL!,\n  privateKey: process.env.RELAYER_PRIVATE_KEY!,\n  recipient: process.env.TREASURY_ADDRESS!\n});\n\n// Any MCP tool endpoint becomes monetizable\napp.post('/api/tools/analyze', x402.requirePayment(\"50000\"), async (req, res) => {\n  const result = await runMCPTool(req.body);\n  res.json({ ...result, paymentTx: req.paymentTx });\n});\n```\n\nM2MCent powers **100+ production MCP servers** on Base Mainnet, processing real USDC micro-payments for AI-to-AI commerce.\n\nMIT © [M2MCent](https://github.com/Evozim/m2mcent-sdk)", "url": "https://wpnews.pro/news/show-hn-x402-express-pay-per-call-http-402-middleware-for-ai-agents-on-base-l2", "canonical_source": "https://github.com/Evozim/m2mcent-sdk", "published_at": "2026-06-04 03:57:29+00:00", "updated_at": "2026-06-04 04:17:55.744440+00:00", "lang": "en", "topics": ["ai-agents", "ai-infrastructure", "ai-products", "ai-tools", "ai-startups"], "entities": ["M2MCent", "X402", "Base L2", "USDC", "EIP-712", "Express", "MCP Servers", "Escrow"], "alternates": {"html": "https://wpnews.pro/news/show-hn-x402-express-pay-per-call-http-402-middleware-for-ai-agents-on-base-l2", "markdown": "https://wpnews.pro/news/show-hn-x402-express-pay-per-call-http-402-middleware-for-ai-agents-on-base-l2.md", "text": "https://wpnews.pro/news/show-hn-x402-express-pay-per-call-http-402-middleware-for-ai-agents-on-base-l2.txt", "jsonld": "https://wpnews.pro/news/show-hn-x402-express-pay-per-call-http-402-middleware-for-ai-agents-on-base-l2.jsonld"}}