Minimal working examples for each supported framework.
Includes a separate agent (client) example that shows how an x402-enabled client pays and calls your gated endpoints. It is not a server adapter.
Each example reads credentials from a .env file. Copy the template and fill in your keys:
cp .env.example .envMONKEPAY_KEY_ID=mk_...
MONKEPAY_KEY_SECRET=sk_...# From the examples/ root
npm install
# Hono — http://localhost:3000
npm run hono
# Express — http://localhost:3000
npm run express
# Fastify — http://localhost:3000
npm run fastify
# Next.js — http://localhost:3000
npm run next
# Agent (client) — pays and calls the API
npm run agentWith no payment (expect 402):
curl http://localhost:3000/api/dataThe 402 response includes the accepts array describing exactly what payment is required — this is what an x402-compatible agent reads to construct and submit payment automatically.
| Example | Framework | Port | Entry |
|---|---|---|---|
hono/ |
Hono | 3000 | app.ts |
express/ |
Express | 3001 | app.ts |
fastify/ |
Fastify | 3002 | app.ts |
next-app/ |
Next.js App Router | 3003 | app/api/data/route.ts |
agent/ |
Client (x402 agent) | — | src/index.ts |