@vergex402/express
v0.5.0
Published
Express middleware for HTTP 402 USDG micropayments on Robinhood Chain via Verge.
Maintainers
Readme
@vergex402/express
Express middleware for x402 v2-compatible HTTP 402 stablecoin micropayments. Defaults to USDG on Robinhood Chain (ID 4663), with explicit Base/Arbitrum/Polygon USDC support through the shared core.
Challenges are emitted in both dialects: the standard PAYMENT-REQUIRED header (base64 PaymentRequired, CAIP-2 networks, atomic amounts) and the legacy X-Pay-* set. Retries are accepted with PAYMENT-SIGNATURE (x402 v2) or X-Pay-Tx + X-Pay-Nonce.
npm install @vergex402/expressQuick start
import express from "express";
import { paywall } from "@vergex402/express";
const app = express();
app.use("/api/premium", paywall({
amount: 0.001, // USDG
recipient: process.env.WALLET!,
network: "robinhood-mainnet",
}));
app.get("/api/premium", (req, res) => {
res.json({ ok: true, message: "unlocked" });
});
app.listen(3000);How it works
- First request to a
paywall()-guarded route returns HTTP 402 Payment Required with a signed challenge. - The caller pays USDG on Robinhood Chain, including the nonce as a memo.
- The caller retries with
X-Pay-Tx: <signature>. The middleware verifies on-chain via the RPC you provide. - If valid, the request flows to your handler.
The middleware rejects a missing nonce and rejects a reused transaction hash. The default replay guard is process-local; pass a durable replayStore backed by Redis, SQLite, or Postgres when running multiple instances.
Options
paywall({
amount, // Price in USDG, e.g. 0.001
recipient, // Your Robinhood Chain address
network, // "robinhood-mainnet"
rpcUrl, // Optional custom EVM RPC
replayStore, // Optional durable { has(txHash), add(txHash) } replay store
verify, // Optional: custom verifier function (req, tx, nonce) → boolean
realm, // Optional: realm name in WWW-Authenticate header (default "verge")
});Self-hosted facilitator
Skip Verge entirely — set rpcUrl to your own EVM RPC endpoint. Zero fees.
paywall({
amount: 0.001,
recipient: process.env.WALLET!,
rpcUrl: "https://my-helius.helius-rpc.com/?api-key=…",
});License
MIT
