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

@x402fly/client

v0.1.2

Published

TypeScript HTTP client for 402fly payment protocol

Readme

@402fly/client

TypeScript HTTP client library for the X402 payment protocol with both manual and automatic payment handling.

Overview

The client package provides HTTP client implementations for making requests to X402-protected resources. It includes two client types:

  • Fly402Client: Manual payment control - you handle 402 responses and payment flow explicitly
  • Fly402AutoClient: Automatic payment handling - automatically detects 402 responses and processes payments

Features

  • Dual Client Modes: Choose between manual or automatic payment handling
  • Solana Wallet Integration: Built-in support for Solana keypair-based payments
  • Retry Logic: Configurable automatic retry with payment
  • Safety Limits: Optional maximum payment amount protection
  • Full TypeScript Support: Complete type definitions and intellisense

Installation

npm install @402fly/client
# or
pnpm add @402fly/client
# or
yarn add @402fly/client

Usage

Automatic Payment Client (Recommended)

The Fly402AutoClient automatically handles payment flow when encountering 402 responses:

import { Fly402AutoClient } from '@402fly/client';
import { Keypair } from '@solana/web3.js';

// Load your wallet keypair
const walletKeypair = Keypair.fromSecretKey(secretKeyBytes);

// Create auto client
const client = new Fly402AutoClient(
  walletKeypair,
  'https://api.devnet.solana.com',
  {
    maxRetries: 1,
    autoRetry: true,
    maxPaymentAmount: '10000000' // Safety limit in lamports
  }
);

// Make requests - payment is handled automatically
const response = await client.fetch('https://api.example.com/premium-data');
console.log(response.data);

// Clean up
await client.close();

Manual Payment Client

The Fly402Client gives you full control over the payment flow:

import { Fly402Client } from '@402fly/client';
import { Keypair } from '@solana/web3.js';

const walletKeypair = Keypair.fromSecretKey(secretKeyBytes);
const client = new Fly402Client(
  walletKeypair,
  'https://api.devnet.solana.com'
);

try {
  // First request
  const response = await client.fetch('https://api.example.com/premium-data');
  console.log(response.data);
} catch (error) {
  if (error.response?.status === 402) {
    // Extract payment request from 402 response
    const paymentRequest = error.response.data;

    // Process payment
    const authorization = await client.makePayment(paymentRequest);

    // Retry with payment authorization
    const response = await client.fetch(
      'https://api.example.com/premium-data',
      {
        headers: {
          'X-Payment-Authorization': authorization.toHeaderValue()
        }
      }
    );
    console.log(response.data);
  }
}

await client.close();

POST Requests with Payment

const client = new Fly402AutoClient(walletKeypair);

// POST request with automatic payment handling
const response = await client.fetch(
  'https://api.example.com/process',
  {
    method: 'POST',
    data: {
      input: 'some data'
    }
  }
);

Custom Configuration

import { Fly402AutoClient } from '@402fly/client';

const client = new Fly402AutoClient(
  walletKeypair,
  'https://api.mainnet-beta.solana.com', // Custom RPC endpoint
  {
    maxRetries: 2,           // Retry up to 2 times
    autoRetry: true,         // Enable automatic retry
    maxPaymentAmount: '5000000' // Maximum 0.005 SOL equivalent
  }
);

API Reference

Fly402AutoClient

Constructor:

constructor(
  walletKeypair: Keypair,
  rpcUrl?: string,
  options?: {
    maxRetries?: number;
    autoRetry?: boolean;
    maxPaymentAmount?: string;
  }
)

Methods:

  • fetch(url: string, options?: AxiosRequestConfig) - Make HTTP request with automatic payment
  • close() - Clean up resources

Fly402Client

Constructor:

constructor(walletKeypair: Keypair, rpcUrl?: string)

Methods:

  • fetch(url: string, options?: AxiosRequestConfig) - Make HTTP request
  • makePayment(paymentRequest: PaymentRequest) - Process payment manually
  • close() - Clean up resources

Documentation

For complete API documentation and guides, visit 402fly.github.io

Testing

pnpm test

Contributing

See CONTRIBUTING.md

License

MIT - See LICENSE