merx-x402
v2.0.0
Published
x402 payment middleware for Express.js -- TRON (USDT/USDC/USDD) and Base (USDC) via MERX facilitator
Maintainers
Readme
merx-x402
Express middleware for x402 payments on TRON and Base via MERX facilitator.
Install
npm install merx-x402Usage
import express from 'express'
import { requirePayment } from 'merx-x402'
const app = express()
// TRON USDT payment ($0.10 per call)
app.get('/api/data', requirePayment({
amount: '0.10',
recipient: 'TYourTronAddress',
}), (req, res) => {
console.log('Paid by:', req.payment.payer, 'tx:', req.payment.txid)
res.json({ data: 'premium content' })
})
// Base USDC payment
app.get('/api/evm', requirePayment({
amount: '0.01',
recipient: '0xYourAddress',
network: 'eip155:8453',
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
}), (req, res) => {
res.json({ data: 'paid via Base' })
})
app.listen(3000)How it works
- Client calls your API without payment
- Middleware returns
402withPAYMENT-REQUIREDheader (x402 v2 format) - Client pays (USDT on TRON or USDC on Base) and retries with
PAYMENT-SIGNATUREheader - Middleware verifies + settles via MERX facilitator
- Your handler runs with
req.paymentcontaining txid, payer, amount
Config
| Option | Required | Default | Description |
|--------|----------|---------|-------------|
| amount | yes | - | Price in USD (e.g. '0.10') |
| recipient | yes | - | Your TRON (T...) or EVM (0x...) address |
| scheme | no | 'exact' | 'exact' or 'upto' |
| network | no | 'tron:0x2b6653dc' | CAIP-2 network identifier |
| asset | no | USDT contract | Token contract address |
| facilitator | no | https://x402.merx.exchange | Facilitator URL |
| apiKey | no | - | MERX API key (unlimited rate) |
| description | no | 'Payment required' | Human-readable description |
Facilitator
MERX is the first x402 facilitator for TRON. Free, no API key required (100 req/day). Get unlimited access at merx.exchange/dashboard/api-keys.
Supported networks: tron:0x2b6653dc (USDT, USDC, USDD), eip155:8453 (USDC on Base).
License
MIT
