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

@100pay-hq/pay402-axios

v1.0.1

Published

A powerful Axios interceptor for handling Pay402 payment requests with wallet integration.

Readme

pay402-axios

A powerful Axios interceptor for handling Pay402 payment requests. It seamlessly integrates with your wallet to handle 402 Payment Required responses, supporting both custom Pay402 flows and standard x402 interactions.

Features

  • Smart Interception: Automatically detects 402 responses.
  • Dual Mode:
    • With Pay402: Handles specialized "gas-free" transfers with pay402 and built in support for multiple payment options including USDT, USDC, SOL, XRP, BNB, etc.
    • With x402: Falls back to x402-axios for standard payment requests.
  • Flexible Payments: Provides multiple payment options and lets you choose your preferred currency.
  • Auto-Retry: Automatically signs the transaction and retries the original request with the proof of payment.

Installation

npm install @100pay-hq/pay402-axios viem axios @100pay-hq/100pay.js

Note: viem is required for the wallet client integration.

Usage

1. Setup your Wallet Client

First, create a wallet client using viem. This is used to sign the payment transactions.

import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';

const account = privateKeyToAccount("0xYourPrivateKey");
const walletClient = createWalletClient({
  account,
  transport: http(),
  chain: baseSepolia,
});

2. Configure the Interceptor

Attach the withPay402Interceptor to your Axios instance. You need to provide a callback function to handle the transaction signing logic.

import axios from 'axios';
import { withPay402Interceptor, PaymentOption } from '@100pay-hq/pay402-axios';
import { Pay100 } from '@100pay-hq/100pay.js'; // Correct import

const client = axios.create({
  baseURL: 'https://api.example.com'
});

// Initialize 100Pay Client
const _100PayClient = new Pay100({
  publicKey: "your_public_key",
  secretKey: "your_secret_key", // Required for server-side operations
});

// Callback to handle the actual payment
const signTransaction = async (pricing: PaymentOption[], resource: string) => {
  console.log('Payment required for resource:', resource);
  console.log('Available payment options:', pricing);
  
  // Example: Prefer 'PAY' token
  // Supported currencies: USDC, USDT, SOL, XRP, BNB, etc.
  const preferredOption = pricing.find(p => p.currency === 'PAY');

  if (!preferredOption) {
    throw new Error('No suitable payment option found');
  }

  console.log(`Paying ${preferredOption.amount} ${preferredOption.currency} to ${preferredOption.payTo}`);

  // Execute an asset transfer using 100Pay.js
  // See docs: https://www.npmjs.com/package/@100pay-hq/100pay.js#asset-transfers
  const transfer = await _100PayClient.transfer.executeTransfer({
    amount: Number(preferredOption.amount),
    symbol: "PAY", // Use 'PAY' as requested
    to: preferredOption.payTo,
    transferType: "internal", // for onchain transfer, use "external" (standard gas fee applies - not recommended for micro payments)
    note: `Payment for ${resource}`,
  });
  
  // Return the transaction hash as proof of payment
  return transfer.transactionHash;
};

// Attach the interceptor
withPay402Interceptor(client, signTransaction, walletClient);

3. Make Requests

Now, just use Axios as normal. If an endpoint requires payment, the interceptor will handle the flow automatically.

try {
  const response = await client.post('/paid-service', { data: 'foo' });
  console.log('Success:', response.data);
} catch (error) {
  console.error('Payment failed:', error);
}

API Reference

withPay402Interceptor(axiosInstance, signTransaction, walletClient)

  • axiosInstance: The Axios instance to wrap.
  • signTransaction: A callback function that receives available payment options and the resource URL, returning a Promise resolving to the transaction ID (hash).
  • walletClient: A viem Wallet Client used for the fallback x402-axios functionality.

SignTransactionCallback

Type: (pricing: PaymentOption[], resource: string) => Promise<string>

PaymentOption

interface PaymentOption {
  amount: string;   // The amount required (e.g., "0.066")
  currency: string; // The currency symbol or name (e.g., "PAY", "USD Coin")
  payTo: string;    // The destination address
}

License

MIT