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

x402-payment-sdk-solana

v1.0.0

Published

TypeScript SDK for x402 HTTP 402 Payment Required protocol on Solana blockchain - Enable micropayments for digital content

Readme

@autonome/x402-payment-sdk

TypeScript SDK for interacting with the x402-payment Solana program.

Installation

npm install @autonome/x402-payment-sdk
# or
yarn add @autonome/x402-payment-sdk

Quick Start

import { X402PaymentSDK, Connection, Keypair, PublicKey } from "@autonome/x402-payment-sdk";

// Connect to Solana
const connection = new Connection("http://localhost:8899", "confirmed");
const sdk = new X402PaymentSDK(connection);

// Create a payment
const payer = Keypair.generate(); // Your payer keypair
const payee = new PublicKey("..."); // Payee address

const { signature, receiptAddress } = await sdk.createPayment(payer, {
  payee,
  amount: X402PaymentSDK.solToLamports(1), // 1 SOL
  resourceId: "article-123",
  memo: "Payment for premium article",
});

console.log("Payment signature:", signature);
console.log("Receipt address:", receiptAddress.toString());

Features

  • ✅ Create payments with automatic fee distribution
  • ✅ Verify payments via on-chain receipts
  • ✅ PDA (Program Derived Address) derivation
  • ✅ Typed interfaces for all program accounts
  • ✅ Helper functions for common operations

API Reference

Constructor

new X402PaymentSDK(connection: Connection, programId?: PublicKey)

Initialize Payment System (One-time)

await sdk.initialize(authority, {
  facilitator: facilitatorPublicKey,
  feeBasisPoints: 500, // 5%
});

Create Payment

const result = await sdk.createPayment(payer, {
  payee: payeePublicKey,
  amount: 1_000_000_000, // 1 SOL in lamports
  resourceId: "unique-resource-id",
  memo: "Optional memo",
});

Verify Payment

const { verified, receipt } = await sdk.verifyPayment(
  payerPublicKey,
  "unique-resource-id",
);

if (verified) {
  console.log("Payment confirmed!");
  console.log("Amount paid:", receipt.amount.toNumber());
  console.log("Fee:", receipt.fee.toNumber());
}

Check if Receipt Exists

const hasPaid = await sdk.hasReceipt(payerPublicKey, "resource-id");

Get Configuration

const config = await sdk.getConfig();
console.log("Facilitator:", config.facilitator.toString());
console.log("Fee:", config.feeBasisPoints / 100, "%");

Utility Functions

// Convert SOL to lamports
const lamports = X402PaymentSDK.solToLamports(1.5); // 1.5 SOL

// Convert lamports to SOL
const sol = X402PaymentSDK.lamportsToSol(1_500_000_000); // 1.5

// Calculate fee
const fee = X402PaymentSDK.calculateFee(1_000_000_000, 500); // 50_000_000 (5%)

PDA Derivation

// Derive config address
const [configAddress, configBump] = sdk.deriveConfigAddress();

// Derive receipt address
const [receiptAddress, receiptBump] = sdk.deriveReceiptAddress(
  payerPublicKey,
  "resource-id",
);

Types

PaymentConfig

interface PaymentConfig {
  authority: PublicKey;
  facilitator: PublicKey;
  feeBasisPoints: number; // 100 = 1%, max 1000 = 10%
  version: number;
  paused: boolean;
  bump: number;
}

Receipt

interface Receipt {
  payer: PublicKey;
  payee: PublicKey;
  amount: anchor.BN;
  fee: anchor.BN;
  timestamp: anchor.BN;
  resourceId: string;
  memo: string;
  isTokenPayment: boolean;
  tokenMint: PublicKey | null;
  signature: number[];
  bump: number;
}

Example: Full Payment Flow

import {
  X402PaymentSDK,
  Connection,
  Keypair,
  PublicKey,
} from "@autonome/x402-payment-sdk";

async function payForContent() {
  // Setup
  const connection = new Connection("http://localhost:8899");
  const sdk = new X402PaymentSDK(connection);
  const payer = Keypair.generate(); // Load from file in production
  const payee = new PublicKey("ContentCreatorAddress...");

  // 1. Check if already paid
  const alreadyPaid = await sdk.hasReceipt(payer.publicKey, "article-123");
  if (alreadyPaid) {
    console.log("Already paid for this content!");
    return;
  }

  // 2. Create payment
  console.log("Creating payment...");
  const { signature, receiptAddress } = await sdk.createPayment(payer, {
    payee,
    amount: X402PaymentSDK.solToLamports(0.1), // 0.1 SOL
    resourceId: "article-123",
    memo: "Premium article access",
  });

  console.log("Payment successful!");
  console.log("Transaction:", signature);
  console.log("Receipt:", receiptAddress.toString());

  // 3. Verify payment
  const { verified, receipt } = await sdk.verifyPayment(
    payer.publicKey,
    "article-123",
  );

  if (verified) {
    console.log("Payment verified on-chain");
    console.log("Amount:", X402PaymentSDK.lamportsToSol(receipt.amount));
    console.log("Fee:", X402PaymentSDK.lamportsToSol(receipt.fee));
  }
}

Development

# Build
npm run build

# Test
npm test

# Lint
npm run lint

# Format
npm run format

License

Apache-2.0

Contributing

Contributions welcome! Please open an issue or PR.