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

monad-x402

v1.0.2

Published

HTTP 402 Payment Protocol SDK for Monad - Axios-compatible payment wrapper with automatic network detection and zero fallbacks

Readme

MonX402

HTTP 402 Payment Protocol Implementation for Monad

MonX402 is a TypeScript SDK implementing the HTTP 402 Payment Required standard on Monad blockchain. It enables API monetization through cryptocurrency micropayments, leveraging Monad's high throughput (10,000 TPS) and 1-second finality for real-time payment settlement.

License: MIT TypeScript Monad

Features

  • 1-Second Finality - Payments settle in under 1 second on Monad
  • EVM Compatible - Built on ethers.js, works with existing Ethereum tooling
  • Autonomous Payments - Designed for AI agents and machine-to-machine transactions
  • Axios-Compatible Client - Drop-in replacement for standard HTTP clients
  • Client-Side Signing - Private keys never leave the user's machine
  • AI Crawler Monetization - Get paid when AI companies crawl your website
  • Universal Bot Protection - Block ALL bots (scrapers, crawlers, etc.) without payment
  • Production Ready - Comprehensive error handling and transaction monitoring

Use Cases

MonX402 is designed for scenarios requiring high-frequency, low-cost API payments:

  • AI Agent Marketplaces - Autonomous agents paying for API access without human intervention
  • High-Frequency Trading APIs - Real-time market data with per-request pricing
  • API Monetization - Convert any Next.js API route into a paid service
  • Microservices Architecture - Internal API billing between services
  • Pay-Per-Use Infrastructure - Charge for actual usage rather than subscriptions

Installation

npm install monad-x402

Quick Start

Client Usage

The SDK provides an Axios-compatible client that handles payment flows automatically:

import { x402axios } from 'monad-x402';

const response = await x402axios.get('https://api.example.com/premium/data', {
  privateKey: process.env.MONAD_PRIVATE_KEY
});

console.log(response.data);
console.log('Transaction hash:', response.paymentInfo?.transactionHash);

Server Setup

Add payment protection to your Next.js API routes using middleware:

// middleware.ts
import { paymentMiddleware } from 'monad-x402';

export const middleware = paymentMiddleware(
  process.env.PAYMENT_RECIPIENT_ADDRESS,
  {
    '/api/premium/crypto-prices': {
      price: '1000000000000000',  // 0.001 MON
      network: 'testnet'
    }
  },
  { url: process.env.FACILITATOR_URL }
);

export const config = {
  matcher: ['/api/premium/:path*']
};

Your API route remains unchanged - the middleware handles all payment logic:

// app/api/premium/crypto-prices/route.ts
import { NextResponse } from 'next/server';

export async function GET() {
  const response = await fetch(
    'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd'
  );
  const data = await response.json();
  
  return NextResponse.json({
    bitcoin: data.bitcoin.usd,
    ethereum: data.ethereum.usd
  });
}

AI Crawler Monetization

Get paid when AI companies crawl your website:

// middleware.ts
import { aiCrawlerMiddleware } from 'monad-x402';

export const middleware = aiCrawlerMiddleware({
  enabled: true,
  price: '1000000000000000',  // 0.001 MON per page
  recipientAddress: process.env.PAYMENT_RECIPIENT_ADDRESS,
  network: 'testnet'
});

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)']  
};

Detects and charges AI crawlers (GPTBot, Claude, Google-Extended, etc.) while allowing regular users free access.

Universal Bot Protection

Block ALL bots - scrapers, crawlers, headless browsers, and automated tools:

// middleware.ts
import { blockAllBotsExceptSEO } from 'monad-x402';

// Allow search engines for SEO, charge everything else
export const middleware = blockAllBotsExceptSEO(
  process.env.PAYMENT_RECIPIENT_ADDRESS,
  '1000000000000000'  // 0.001 MON
);

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)']  
};

Detects and blocks:

  • Search engines - Googlebot, Bingbot, Baidu, Yandex
  • AI crawlers - GPT, Claude, Gemini, Perplexity
  • Scrapers - Scrapy, cURL, Wget, Python Requests
  • SEO tools - Ahrefs, Semrush, Screaming Frog
  • Headless browsers - Puppeteer, Playwright, Selenium
  • Any automated tool - Pattern + behavioral detection

Architecture

┌─────────────┐                    ┌─────────────┐
│   Buyer     │                    │   Seller    │
│  (Client)   │                    │  (API)      │
└──────┬──────┘                    └──────┬──────┘
       │                                  │
       │  1. GET /api/premium/data       │
       │─────────────────────────────────>│
       │                                  │
       │  2. 402 Payment Required         │
       │<─────────────────────────────────│
       │     (payment requirements)       │
       │                                  │
       │  3. Build & Sign Transaction     │
       │     (client-side, secure)        │
       │                                  │
       │  4. GET with X-PAYMENT header    │
       │─────────────────────────────────>│
       │                                  │
       │              ┌──────────────┐    │
       │              │ Facilitator  │    │
       │              │   Service    │    │
       │              └──────┬───────┘    │
       │                     │            │
       │  5. Verify Payment  │            │
       │     ────────────────>            │
       │     <────────────────            │
       │                     │            │
       │  6. Return Data     │            │
       │<─────────────────────────────────│
       │                     │            │
       │  7. Settle on Chain │            │
       │     ────────────────>            │
       │                     ▼            │
       │              ┌──────────────┐    │
       │              │    Monad     │    │
       │              │  Blockchain  │    │
       │              └──────────────┘    │

Configuration

Environment Variables

# Client
MONAD_PRIVATE_KEY=0x...

# Server
PAYMENT_RECIPIENT_ADDRESS=0x...
MONAD_NETWORK=testnet
FACILITATOR_URL=http://localhost:3000/api/facilitator

Network Configuration

import { createMonadProvider } from 'monad-x402';

const provider = createMonadProvider('testnet');

API Reference

Client API

const response = await x402axios.get(url, {
  privateKey: string,
  headers?: Record<string, string>,
  timeout?: number
});

response.paymentInfo = {
  transactionHash: string,
  amount: string,
  recipient: string,
  network: string
};

Middleware API

interface RouteConfig {
  price: string;           // Amount in wei
  network: 'testnet' | 'mainnet';
  config?: {
    description?: string;
    mimeType?: string;
    maxTimeoutSeconds?: number;
  };
}

Utility Functions

import {
  createMonadWallet,
  buildTransferTransaction,
  signTransaction,
  submitTransaction,
  formatMON,
  parseMON,
  getBalance
} from 'monad-x402';

Development

npm run demo          # Run demo
npm run build:sdk     # Build SDK
npm run build         # Build all

Monad Testnet

  • RPC: https://testnet-rpc.monad.xyz
  • Chain ID: 10143
  • Explorer: https://testnet-explorer.monad.xyz

Security

Private keys are signed client-side and never transmitted over the network. The implementation uses ethers.js for transaction signing and is fully open source.

Contributing

Contributions are welcome. Please submit pull requests or open issues on GitHub.

License

MIT License - see LICENSE file for details.

Links

Roadmap

  • Mainnet support
  • ERC-20 token payments
  • Batch payment support
  • Payment streaming
  • Multi-language SDK support