cd /news/ai-agents/show-hn-x402-express-pay-per-call-ht… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-21112] src=github.com pub= topic=ai-agents verified=true sentiment=↑ positive

Show HN: X402-express. Pay-per-call HTTP 402 middleware for AI agents on Base L2

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.

read2 min publishedJun 4, 2026

Ultra-lightweight x402 payment interceptor for AI Agents and MCP Servers. Monetize any API in 3 lines of code.

npm install m2mcent-sdk
js
import { X402Handler } from 'm2mcent-sdk';

const x402 = new X402Handler({
  rpcUrl: 'https://mainnet.base.org',
  privateKey: process.env.RELAYER_PRIVATE_KEY!,
  recipient: process.env.TREASURY_ADDRESS!
});

// Protect any Express endpoint with a USDC paywall
app.post('/api/analyze', x402.requirePayment("100000"), (req, res) => {
  res.json({ result: "Premium analysis complete", receipt: req.paymentTx });
});

M2MCent implements the x402 Payment Protocol β€” a machine-native payment standard inspired by HTTP 402:

Agent requests a protected endpointServer responds with402 Payment Required

  • 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 contractAgent receives the premium response + transaction receipt
Agent ──► API Server ──► 402 + metadata
Agent ◄── signs EIP-712 authorization
Agent ──► API Server + Payment-Signature header
          └──► Escrow.settle() on Base L2
Agent ◄── Premium Response + tx hash
Parameter Description Required
rpcUrl
Base Mainnet RPC endpoint βœ…
privateKey
Relayer wallet private key (for settlement) βœ…
recipient
Treasury address to receive payments βœ…

Non-custodial: Funds flow directly from payer β†’ treasury via on-chain escrow** Gasless for payers**: Uses EIP-3009transferWithAuthorization

(USDC native)Zero-Leak: No agent data is retained after settlement** Atomic**: Payment and service delivery happen in a single request cycle

Parameter Value
Network
Base Mainnet (Chain ID: 8453)
USDC Contract
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Escrow Contract
0xf3c3416A843d13C944554A54Ac274BB7fF264BcC
Settlement
Atomic, sub-second finality

Perfect for Model Context Protocol servers:

import express from 'express';
import { X402Handler } from 'm2mcent-sdk';

const app = express();
const x402 = new X402Handler({
  rpcUrl: process.env.BASE_RPC_URL!,
  privateKey: process.env.RELAYER_PRIVATE_KEY!,
  recipient: process.env.TREASURY_ADDRESS!
});

// Any MCP tool endpoint becomes monetizable
app.post('/api/tools/analyze', x402.requirePayment("50000"), async (req, res) => {
  const result = await runMCPTool(req.body);
  res.json({ ...result, paymentTx: req.paymentTx });
});

M2MCent powers 100+ production MCP servers on Base Mainnet, processing real USDC micro-payments for AI-to-AI commerce.

MIT Β© M2MCent

── more in #ai-agents 4 stories Β· sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/show-hn-x402-express…] indexed:0 read:2min 2026-06-04 Β· β€”