An x402 seller server and buyer client, with the spend guards, the pre-flight checker, and nine failure modes measured in real operation — each one with the test that separates the real cause from the apparent one.
The code for an x402 endpoint is the easy part. Starter kits exist, some of them good, and they all stop in the same place: the server boots, the 402 shows up, the example ends.
What comes after that isn't documented anywhere:
verify reverts on it.None of these warn you when they go wrong. None of them show up in a unit test.
This package is the code of an endpoint that settled a real payment on mainnet — USDC on Base, through the CDP facilitator, with the funds landing in the seller's wallet — plus the document that records each of those traps with the discriminating test that tells the real cause from the apparent one.
US$ 29 · paid in USDC on Base
No account, no signup, no middleman.
.zip back, once the settlement is confirmed on-chain.Delivery is manual, checked one by one. If the transaction doesn't confirm, nothing is charged and nothing is sent.
@x402/express; a 402 with machine-readable terms, settlement through the CDP facilitator on mainnet and the public facilitator on testnet.--confirm, and --confirm is refused when the advertised destination can't be indexed.payTo mismatch (the server aborts at boot), shared-tunnel domain, unknown balance. In the right order, and the order is deliberate.payTo, advertised price against configured price, endpoint, public reachability; it prints the origin of every value and warns citing both when the environment and the file disagree.process.env directly.429.PITFALLS.md — nine sections, each with "what it looks like", "what it is", and "how to tell them apart".For anyone putting an x402 endpoint on mainnet who would rather not discover these things the way they were discovered here — one at a time, each costing a day or a payment.
It also helps if you already have an endpoint live and can't explain why it isn't indexed, why the purchase fails, or why the number the checker prints isn't the one the server advertises.
Assumes TypeScript and Node ≥ 20. Assumes no prior experience with x402.
MIT. Derivative work of Conway-Research/automaton, with the original copyright notice and license text kept inside the package (LICENSE + NOTICE). You may use, modify, and redistribute it, including commercially.
One .zip, 55 files. pnpm install && pnpm test runs the whole suite with no network and no paid service.