b402-express middleware to create paid API routes that require crypto payments before access.
Currently, a TypeScript SDK is available for developers. Additional SDKs including Python will be released soon.
b402 does not require you to set up API keys. The b402 facilitator verifies signatures and submits transactions.
Installation
First, install the seller middleware package:Basic Setup
Import and configure the middleware in your Express app, specifying your wallet address and the services you want to sell:Route Configuration
Protected/Paid Routes
Endpoints listed in the middleware configuration require payment before access. When called without valid proof of payment, the middleware automatically returns an HTTP 402 (Payment Required) response containing all necessary payment details.Free Routes
Any route not listed in the configuration remains free and accessible as usual.Payment Details
When a protected endpoint is accessed without payment, the middleware returns a JSON payload with:- Token contract address
- Your receiving wallet (payTo)
- Required amount
- Relayer contract address (0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a)
- Description of the payment