Prerequisites
Prerequisites
- A crypto 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+ installed.
1. Install dependencies
- Express
- Next.js
- Hono
- Go
- FastAPI
- Flask
2. Add payment middleware
Add the x402 payment middleware to your server. The middleware intercepts incoming requests, returns a402 Payment Required response if no payment is attached, and verifies/settles
payments through Abstract’s facilitator.
Replace 0xYourWalletAddress with the wallet address where you want to receive payments.
- Express
- Next.js (Route Handler)
- Hono
- Go (Gin)
- FastAPI
- Flask
3. Test your integration
With your server running, send a request to the protected endpoint:402 Payment Required response with a PAYMENT-REQUIRED header containing the payment requirements. This confirms the middleware is working — clients using an x402 client SDK will handle payment automatically.
Using testnet
The examples above use Abstract mainnet (eip155:2741). To use Abstract testnet during development,
change the network ID to eip155:11124:
https://facilitator.x402.abs.xyz supports both networks.
Next steps
- Making Payments — build a client that pays for x402-protected resources.
- x402 Documentation — advanced topics like lifecycle hooks and Bazaar discovery.
- x402 Examples — complete working examples on GitHub.