Installation
Quick Start
How It Works
The middleware intercepts incoming requests and:- Checks for payment headers (
X-PaymentorX402-PAYMENT) - Verifies the payment signature and amount
- Returns
nullif valid (allowing your handler to proceed) - Returns a
Responsewith 402 status if payment is missing or invalid
Configuration
Required Options
Settlement Modes
Control how payments are settled after verification:Verification Backend
Use your deployed verification backend in production.Response Format
On successful payment verification, the middleware returns aResponse with:
Headers:
X-Payment-Verified: trueX-Payer-Address: 0x...
Error Responses
402 Payment Required
No payment header was provided.402 Verification Failed
Payment signature or amount was invalid.400 Settlement Failed
Settlement mode wassettle but on-chain transaction failed.
Tips
The
amount can be specified as a human-readable string like "1.0" for 1 token, or as a bigint for precise control over decimals.Advanced Mix-and-Match Config (Current API)
UsepaymentMiddleware for per-token/per-network facilitator routing and extension-aware challenge headers:
requirements:
/supported capability response.