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/core

v0.1.2

Published

Core TypeScript library for 402fly payment protocol

Readme

@402fly/core

Core TypeScript implementation of the X402 payment protocol for autonomous AI agent payments on Solana.

Overview

The core package provides fundamental primitives and utilities for implementing the X402 payment protocol. It includes payment request/authorization models, Solana payment processing, error handling, and serialization utilities.

Features

  • Payment Models: PaymentRequest and PaymentAuthorization classes with full serialization support
  • Solana Integration: SolanaPaymentProcessor for handling on-chain payment verification
  • Error Handling: Comprehensive error types for payment lifecycle management
  • Type Safety: Full TypeScript support with exported types and interfaces

Installation

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

Usage

Payment Request

import { PaymentRequest } from '@402fly/core';

// Create a payment request
const paymentRequest = new PaymentRequest({
  max_amount_required: '1000000',
  asset_type: 'spl-token',
  asset_address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
  payment_address: 'YourWalletAddress',
  network: 'solana-devnet',
  expires_at: new Date(Date.now() + 3600000),
  nonce: 'unique-nonce',
  payment_id: 'payment-123',
  resource: '/api/data',
  description: 'Access to premium API endpoint'
});

// Check if expired
if (paymentRequest.isExpired()) {
  console.log('Payment request has expired');
}

// Serialize to JSON
const json = paymentRequest.toJSON();

Payment Authorization

import { PaymentAuthorization } from '@402fly/core';

// Create payment authorization
const authorization = new PaymentAuthorization({
  payment_id: 'payment-123',
  actual_amount: '1000000',
  payment_address: 'WalletAddress',
  asset_address: 'TokenMintAddress',
  network: 'solana-devnet',
  timestamp: new Date(),
  signature: 'base58-signature',
  public_key: 'base58-public-key',
  transaction_hash: 'transaction-signature'
});

// Convert to HTTP header value
const headerValue = authorization.toHeaderValue();

Solana Payment Processing

import { SolanaPaymentProcessor } from '@402fly/core';
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://api.devnet.solana.com');
const processor = new SolanaPaymentProcessor(connection);

// Verify a payment
const isValid = await processor.verifyPayment(
  paymentRequest,
  paymentAuthorization
);

Error Handling

import {
  PaymentRequiredError,
  PaymentExpiredError,
  InsufficientFundsError,
  PaymentVerificationError,
  ERROR_CODES
} from '@402fly/core';

try {
  // Payment operations
} catch (error) {
  if (error instanceof PaymentExpiredError) {
    console.error('Payment has expired');
  } else if (error instanceof InsufficientFundsError) {
    console.error('Insufficient funds');
  }
}

API Reference

Exports

  • PaymentRequest - Payment request model class
  • PaymentAuthorization - Payment authorization model class
  • SolanaPaymentProcessor - Solana blockchain payment processor
  • Error classes: Fly402Error, PaymentRequiredError, PaymentExpiredError, InsufficientFundsError, PaymentVerificationError, TransactionBroadcastError, InvalidPaymentRequestError
  • ERROR_CODES - Error code constants

Documentation

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

Testing

pnpm test

Contributing

See CONTRIBUTING.md

License

MIT - See LICENSE