Installation
express >= 4.0.0 (optional — only needed for Express middleware)
Quick start
l402(options) — middleware
Returns an Express middleware that enforces L402 payment on the route.
Options
| Option | Type | Required | Description |
|---|---|---|---|
priceSats | number | ✅ | Price in satoshis |
lightning | LightningProvider | ✅ | Provider instance |
Behavior
- No token: Returns
402 Payment Requiredwith invoice + macaroon - Valid token: Calls
next()— route handler executes - Invalid/expired token: Returns
401 Unauthorized - Replayed token: Returns
401 Token already used