x402-paid-agent-starter / tree / typescript/README.md ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)

x402 paid agent starter: TypeScript

npm install
PAY_TO=0xYourBaseAddress NETWORK=base-sepolia npm start   # http://localhost:8402
curl -i http://localhost:8402/paid                          # 402 with the payment terms
PAYER_KEY=0x... npm run pay                                 # pays one call (testnet USDC) and prints the settlement
import { createApp } from './src/app.js';
const app = createApp({ price: '0.01', payTo: process.env.PAY_TO!, network: 'base', facilitator: 'https://facilitator.payai.network' });
export default app; // { fetch(request) } works as a Cloudflare Worker or Bun server

List the agent on LAX (costs 0.01 USDC on Base, paid over x402):

LAX_PAYER_KEY=0x... npm run list   # prints: listed: lax-ext-...

Before listing, set endpoint in lax-offer.json to your deployed /paid URL on your own domain. The registry checks the offer for free: an unpaid POST answers 402 with "Your offer is valid" (npm run test:live does this, and nothing is listed).

Tests: npm test runs A1 to A6 offline with a fake facilitator and a fake registry.

Base Sepolia proof

One paid call, settled on chain through the x402.org facilitator on 21 October 2026 (20:58:30 UTC):

https://sepolia.basescan.org/tx/0x352aa808ef460fdaf8de6a9ba8a0e5bac7f2cf7b26c426f6b9440cd0de13cacf

0.01 USDC (10000 atomic, asset 0x036CbD53842c5426634e7929541eC2318f3dCF7e) moved from the payer 0x3c1A1E01e790Cd326495631B3b38Bd7068F08d6F to the starter's PAY_TO 0x9B29122f4e77Deb78bBb2580EDb07C08ff22DbA7 in block 48472205. The response was 200, with the work output and an X-PAYMENT-RESPONSE holding the same transaction hash.

Reproduce it:

PAY_TO=0xYourTestAddress NETWORK=base-sepolia PRICE_USDC=0.01 npm start   # terminal 1
PAYER_KEY=0x... URL=http://localhost:8402/paid npm run pay                # terminal 2

agentgate-source: code mirror on Cloudflare Pages. All repos