Accept crypto payments in your Express API with the Armory middleware.
Installation
# npm
npm install @armory-sh/middleware-express
# yarn
yarn add @armory-sh/middleware-express
# pnpm
pnpm add @armory-sh/middleware-express
# bun
bun add @armory-sh/middleware-express
Quick Start
import express from 'express';
import { paymentMiddleware } from '@armory-sh/middleware-express';
const app = express();
// Protect all routes with payment
app.use(paymentMiddleware({
requirements: {
to: '0xYourWalletAddress...',
amount: 1000000n, // 1 USDC (6 decimals)
expiry: Date.now() + 3600 * 1000,
chainId: 'eip155:8453',
assetId: 'eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
}
}));
app.get('/api/data', (req, res) => {
res.json({ message: 'Payment successful!' });
});
app.listen(3000);
Accessing Payment Info
The middleware attaches payment information to every request:
app.get('/api/user', (req, res) => {
const { payerAddress, payload, version } = req.payment;
res.json({
message: `Hello ${payerAddress}`,
paid: payload.amount
});
});
Protecting Specific Routes
You can apply the middleware to specific routes only:
// Public route — no payment required
app.get('/api/public', (req, res) => {
res.json({ message: 'Anyone can access this' });
});
// Protected route — payment required
app.get('/api/premium',
paymentMiddleware({ /* config */ }),
(req, res) => {
res.json({ message: 'Paid content' });
}
);
Route Configuration
For per-route pricing or requirements, use routeAwarePaymentMiddleware:
import { routeAwarePaymentMiddleware } from '@armory-sh/middleware-express';
app.use('/api', routeAwarePaymentMiddleware({
'/api/basic': { requirements: basicRequirements },
'/api/premium': { requirements: premiumRequirements },
}));
Tips
Want to accept payments on Base using USDC? Use token address 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 with 6 decimals.
Express middleware runs sequentially — place paymentMiddleware before any routes that require payment protection.
See @armory-sh/middleware-express for full configuration options.