Accept crypto payments in your Hono API with the Armory middleware.
Installation
# npm
npm install @armory-sh/middleware-hono
# yarn
yarn add @armory-sh/middleware-hono
# pnpm
pnpm add @armory-sh/middleware-hono
# bun
bun add @armory-sh/middleware-hono
Quick Start
import { Hono } from 'hono';
import { acceptPaymentsViaArmory } from '@armory-sh/middleware-hono';
const app = new Hono();
// Protect all routes
app.use('*', acceptPaymentsViaArmory({
payTo: '0xYourWalletAddress...',
amount: '1.0'
}));
app.get('/api/data', (c) => {
return c.json({ message: 'Payment successful!' });
});
app.listen(3000);
Accessing Payment Info
Payment information is stored in the Hono context:
app.get('/api/user', (c) => {
const payment = c.get('payment');
const { payerAddress, payload } = payment;
return c.json({
message: `Hello ${payerAddress}`,
paid: payload.amount
});
});
Protecting Specific Routes
Use path patterns to protect specific route groups:
// Public routes — no payment
app.get('/', (c) => c.json({ message: 'Welcome' }));
// All /api/* routes require payment
app.use('/api/*', acceptPaymentsViaArmory({
payTo: '0x...',
amount: '1.0'
}));
app.get('/api/data', (c) => c.json({ data: '...' }));
Multi-Network Support
Accept payments across multiple networks:
app.use('/api/*', acceptPaymentsViaArmory({
payTo: '0x...',
amount: '1.0',
accept: {
networks: ['base', 'ethereum', 'polygon'],
tokens: ['usdc', 'usdt']
}
}));
Route Configuration
For route-specific configuration, use routeAwarePaymentMiddleware:
import { routeAwarePaymentMiddleware } from '@armory-sh/middleware-hono';
app.use('/api/*', routeAwarePaymentMiddleware({
routes: ['/api/basic', '/api/premium/*'],
payTo: '0xYourAddress...',
amount: '$1.00',
network: 'base',
perRoute: {
'/api/premium/*': {
amount: '$5.00'
}
}
}));
Tips
The amount parameter accepts human-readable strings like "1.0" for 1 token — no need to calculate decimals manually.
Hono’s middleware matching is pattern-based. Use /api/* to protect all API routes, or /premium/* for paid content only.
See @armory-sh/middleware-hono for full configuration options.