- SDK References
- Payment Protocol Adapters
- x402-sdk
x402-server
On this page
Protect Express routes with @fastxyz/x402-server
@fastxyz/x402-server exports Express-compatible paywall() and paymentMiddleware() helpers. See the package README for exact route, price, asset, network, and facilitator configuration.
npm install @fastxyz/x402-serverimport express from 'express';import { paywall } from '@fastxyz/x402-server';
const app = express();app.use('/premium', paywall( { fast: 'fast1merchant...' }, { price: '$0.10', network: 'fast-testnet', networkConfig: { asset: tokenId, decimals: 6 } }, { url: 'https://facilitator.example.com' },));app.get('/premium', (_req, res) => res.json({ content: 'paid resource' }));Without a payment payload, middleware returns 402 Payment Required with the requirement. A present payload is checked through the facilitator; invalid payment does not authorize the handler and is also represented by a payment-required response, not a generic 403 contract. Verify the network, asset, recipient, amount, and facilitator you configure; a valid proof for some other requirement must not grant this route.
The exported middleware is Express-shaped. Other frameworks need a tested adapter rather than an assumption that their middleware signatures are identical. For multi-route pricing, use paymentMiddleware() with the documented route map. Do not assume a proof is reusable or that a transport failure means no payment occurred.