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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@x402-iota/server-express

v0.1.1

Published

Express middleware for x402-iota payments

Readme

@x402-iota/server-express

Express middleware for x402 payment gateway on IOTA blockchain.

Overview

Add payment requirements to Express routes with simple configuration.

Installation

npm install @x402-iota/server-express @x402-iota/core

Quick Start

import express from "express";
import { x402Middleware } from "@x402-iota/server-express";

const app = express();

app.use(
  x402Middleware({
    facilitatorUrl: "http://localhost:3001",
    payToAddress: "0x1234567890123456789012345678901234567890",
    network: "iota-evm-testnet",
    asset: "0xFbDa5F676cB37624f28265A144A48B0d6e87d3b6", // USDC
    routes: {
      "/api/protected": {
        amount: "1000000", // 1 USDC
        description: "Access protected API",
      },
      "/api/premium/*": {
        amount: "5000000", // 5 USDC
        description: "Premium content",
      },
    },
  })
);

// Routes
app.get("/api/public", (req, res) => {
  res.json({ message: "Public data" });
});

app.get("/api/protected", (req, res) => {
  // Payment verified automatically by middleware
  const paymentInfo = req.x402;
  console.log("Payment verified:", paymentInfo);
  res.json({ message: "Protected data" });
});

app.listen(3000, () => {
  console.log("Server running on :3000");
});

Configuration

interface X402ExpressOptions {
  facilitatorUrl: string; // Facilitator service URL
  payToAddress: string; // Recipient wallet
  network: Network; // IOTA network
  asset: string; // Token contract address
  routes: Record<string, RouteConfig>; // Protected routes
  onChainVerification?: boolean; // Verify on-chain (default: false)
}

interface RouteConfig {
  amount: string; // Payment amount (atomic units)
  description?: string; // Human-readable description
}

Middleware Flow

Request
   ↓
Check route matches config
   ↓
If matches:
  - Check X-PAYMENT header
  - If missing → Return 402
  - If present → Verify payment
  - If valid → Continue
  - If invalid → Return 402
If doesn't match:
  - Continue (no payment required)

Response Format

Success (200)

{
  data: { ... },
  timestamp: "2025-11-15T..."
}

Payment Required (402)

{
  x402Version: 1,
  accepts: [{
    scheme: 'exact',
    network: 'iota-evm-testnet',
    maxAmountRequired: '1000000',
    resource: '/api/protected',
    description: 'Access protected API',
    mimeType: 'application/json',
    payTo: '0x...',
    maxTimeoutSeconds: 3600,
    asset: '0x...',
    extra: { name: 'USD Coin', version: '2' }
  }]
}

Related Packages

License

MIT