Prerequisites
Prerequisites
- A wallet address to receive payments
- An existing HTTP API built with Express, Next.js, Hono, Gin, FastAPI, or Flask
- Node.js 18+, Go 1.21+, or Python 3.10+
1. Install dependencies
- Express
- Next.js
- Hono
- Go
- Python
2. Add payment middleware
Wrap your paid routes with x402 middleware and point it at the Abstract facilitator.3. Shape the paid resource
For agent-facing APIs, define:- a stable route
- a clear description
- a deterministic response format
- a price that is cheap enough for repeated automated use
4. Test the flow
The protected route should:- return
402 Payment Requiredwhen called without payment - advertise the payment requirements in the response
- return
200once the client retries with a valid payment
Next
- Continue to
Make x402 Paymentsto test a paying client - Compare with
MPPif you expect repeated micro-payments