Prerequisites
Before you begin, make sure you have:- Bun v1.3+ (or Node.js 18+)
- A wallet address on Base Sepolia (testnet) — get testnet USDC from faucet.circle.com (select Base Sepolia)
- Redis running locally or remotely (Postgres is also supported — see Storage)
Setup
Configure and mount
Create a
server.ts file. Key0 mounts as middleware on your existing server — it adds the discovery endpoint (/.well-known/agent.json), the challenge/proof routes (/x402/access, /x402/proof), and leaves your existing routes untouched.Set environment variables
Create a
.env file in your project root:.env
ACCESS_TOKEN_SECRET must be at least 32 characters. This secret is used to sign JWTs issued to agents after payment. Use a cryptographically random string.Run and test
Start your server:Test the discovery and access endpoints with curl:The first call returns the A2A agent card with your pricing. The second returns an x402 challenge containing the payment amount, destination wallet, and chain ID. A client agent uses this to submit payment on-chain and then prove it.
Discovery
Request access (returns 402 challenge)

