npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dual402

v0.1.5

Published

One Express middleware for paid APIs: accept x402 and MPP payments, with OpenAPI and /.well-known/x402 discovery.

Downloads

385

Readme

dual402

dual402 is one Express integration for paid APIs that accepts both x402 and MPP payments. Add a price and schema once, and the same middleware handles payment challenges, verification, and discovery metadata for scanners, agent markets, and agent clients.

  • One integration: support x402 and MPP clients without implementing both protocols yourself.
  • Monetization: charge pay-per-request USDC without building a billing system.
  • Discoverability: publish OpenAPI and /.well-known/x402 from the same route definition.
  • Express ergonomics: validate first, charge, then run the handler.

Install

npm i dual402

Node 22 or newer is required. express@^5 is a peer dependency; install it separately when you are starting from an empty project.

Quickstart: Monetize + Discover

The key helper is paidRoute(): it creates the payment middleware and the discovery metadata together.

import express from "express";
import { createDual402, dualDiscovery, paidRoute } from "dual402";

const app = express();
app.use(express.json());

function requiredEnv(name) {
  const value = process.env[name];
  if (!value) throw new Error(`Missing required env var: ${name}`);
  return value;
}

const facilitatorUrl = requiredEnv("X402_FACILITATOR_URL");
const cdpAuth =
  new URL(facilitatorUrl).host === "api.cdp.coinbase.com"
    ? {
        apiKeyId: requiredEnv("CDP_API_KEY_ID"),
        apiKeySecret: requiredEnv("CDP_API_KEY_SECRET"),
      }
    : undefined;

const dual = createDual402({
  mpp: {
    currency: requiredEnv("USDC_TEMPO"),
    recipient: requiredEnv("MPP_RECIPIENT"),
    secretKey: requiredEnv("MPP_SECRET_KEY"),
    testnet: process.env.MPP_TESTNET === "true",
  },
  x402: {
    payTo: requiredEnv("X402_PAYEE_ADDRESS"),
    network: requiredEnv("X402_NETWORK"),
    facilitatorUrl,
    ...(process.env.X402_ASSET && { asset: process.env.X402_ASSET }),
    ...(cdpAuth && { cdpAuth }),
  },
});

const quote = paidRoute(dual, {
  method: "get",
  path: "/quote",
  amount: "0.02",
  operationId: "getQuote",
  summary: "Get a quote",
  parameters: [
    { name: "symbol", in: "query", required: true, schema: { type: "string" } },
  ],
  responseSchema: {
    type: "object",
    properties: {
      symbol: { type: "string" },
      price: { type: "number" },
    },
    required: ["symbol", "price"],
  },
});

function validateQuote(req, res, next) {
  const symbol = String(req.query.symbol ?? "").trim();
  if (!symbol) return res.status(400).json({ error: "symbol is required" });
  req.symbol = symbol.toUpperCase();
  return next();
}

app.get(quote.path, validateQuote, quote.handler, (req, res) => {
  res.json({ symbol: req.symbol, price: 42 });
});

dualDiscovery(app, dual, {
  info: { title: "Quote API", description: "", version: "1.0.0" },
  serviceName: "Quote API",
  tags: ["finance", "quotes"],
  routes: [quote],
});

That is the collapsed flow: /quote is monetized, discoverable, and still just an Express route. Invalid requests stay free, valid unpaid requests receive x402 and MPP payment options, and paid retries continue to the protected handler.

Example

cp .env.example .env
npm run build
node --env-file=.env examples/minimal-api.js
curl -i "http://localhost:8080/quote?symbol=ETH"
curl    "http://localhost:8080/openapi.json"
curl    "http://localhost:8080/.well-known/x402"

Config

Start from .env.example. The required values are:

  • MPP: MPP_SECRET_KEY, USDC_TEMPO, MPP_RECIPIENT, MPP_TESTNET
  • x402: X402_PAYEE_ADDRESS, X402_NETWORK, X402_FACILITATOR_URL
  • recommended behind proxies: BASE_URL

For Base mainnet, use Coinbase's CDP facilitator and credentials:

X402_NETWORK=eip155:8453
X402_FACILITATOR_URL=https://api.cdp.coinbase.com/platform/v2/x402
CDP_API_KEY_ID=...
CDP_API_KEY_SECRET=...

createDual402() fails fast for common money-routing mistakes, including Base mainnet with the public Sepolia facilitator and CDP facilitator usage without CDP credentials.

API

  • createDual402(config) validates shared x402 and MPP configuration.
  • paidRoute(dual, options) creates route middleware and discovery metadata.
  • dualDiscovery(app, dual, config) mounts GET /openapi.json and GET /.well-known/x402. Set serviceName, tags, and iconUrl to surface Bazaar-style identity metadata in the x402 resource object and discovery manifest.
  • dual.charge({ amount, description?, waitForSettle? }) is the lower-level middleware factory when you do not need discovery metadata.

For production integration details, hand the packaged agent guide to your coding agent:

Install dual402, read node_modules/dual402/AGENTS.md, and make my Express API
accept paid requests through both x402 and MPP with one middleware.

Testing

npm test

License

MIT