x402-lab — Test AI-Agent Payments Before They Cost Real Money
Problem
AI agents can now pay for APIs over x402 (HTTP 402) in USDC, but there is no safe place to test it. Every try on a testnet or mainnet facilitator needs a funded wallet, a facilitator can verify a payment and still fail to settle it, and failures come back as opaque codes like invalid_exact_evm_transaction_simulation_failed.
Business Impact
x402 lets AI agents pay for APIs per request, and a payment bug either takes the buyer's money or the seller's revenue. Testing it today means a funded wallet and real settlements. x402-lab makes that loop free and local, and it catches the failure that hurts most: while building it, rate-limited receipt polling made the stock stack charge the agent and still answer 402. Conformance check C04 flags that by comparing the response with on-chain balances.
System Approach
- One command (x402-lab dev) boots Anvil, an EIP-3009 test USDC, Multicall3, the official @x402/evm facilitator, an @x402/hono paid API and the dashboard in about a second; a local payment settles in ~170 ms
- Route-map dashboard: every request is drawn as a train from the agent to the chain, and failures exit down branch lines to counted termini with the last reason
- Five chaos modes inside the facilitator: settle-fail, rpc-rate-limit (settlement_pending), hang, latency and flaky
- 35 conformance checks across the resource server, the chain and the facilitator, runnable against the lab or any paid endpoint, with JSON output and a non-zero exit code for CI
- Error decoder for 139 codes from the reference TypeScript, Go and Python SDKs and FiatToken reverts, plus schema checks for PAYMENT-* headers and JSON
- Programmatic API (Lab.start, runConformance) for test suites and GitHub Actions
Key Decisions & Trade-offs
- Test the official SDKs, never reimplement the protocol: @x402/core, @x402/evm, @x402/hono and @x402/fetch run as shipped
- LabUSDC mirrors USDC's EIP-712 domain and revert strings, so real x402 payloads verify and settle unchanged
- Multicall3 is installed on boot — without it the reference facilitator reports nonce, balance and token-domain failures as one generic simulation error
- Safe with real keys: negative tests sign with a throwaway key, and a real key signs one payment only for the named --asset, under --max-amount, on the --rpc chain, valid for at most 600 seconds
- The dashboard API only answers localhost Host and Origin headers and JSON requests, which blocks CSRF and DNS rebinding
- A zero-build vanilla JS dashboard, so the whole lab ships inside npx
Current Status
Public and open source (MIT) at github.com/rohitguta2432/x402-lab since October 17, 2026. 26 automated tests, including end-to-end runs that settle real EIP-3009 payments on Anvil, run in GitHub Actions. Install with npx github:rohitguta2432/x402-lab dev (Node 20+ and Foundry).
Roadmap
- Solana (SVM) lane next to the EVM one
- upto, Permit2 and ERC-7710 transfer methods
- Validator for origin-hosted discovery (/.well-known/x402.json)
- MCP server so coding agents can run the suite
What I'd Improve Next
- Publish to npm so the install becomes npx x402-lab
- Record and replay real facilitator traffic
Explore More
- OpScope — Find Where a UserOperation Failed, and Prove It — When an ERC-4337 UserOperation fails, the bundler returns a two-word code like AA24 or AA31, or the operation is included and its call quietly reverts.
- OrderPilot — From Purchase Order PDF to Reviewed Sales-Order Draft — Electrical-parts distributors receive purchase orders as PDFs and emails written in the customer's own words: '20A single pole breaker', '#12 THHN black copper, 1500 FT'.
- dpdp-scan — Find Where Your Code Leaks Indian Personal Data — India's DPDP Rules were notified in November 2025 and the core obligations apply from 13 May 2027.
- MyFinancial — Personal Financial Advisor — Financial planning in India is fragmented across banks, insurance, and tax documents.
- All 36 projects — the full catalogue, with live links and repos.