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

pumpfun-toolkit

v1.0.6

Published

A Node.js toolkit for trading on PumpFun protocol

Readme

PumpFun Toolkit

A Node.js toolkit for trading on the PumpFun protocol, providing easy-to-use functions for buying and selling tokens using bonding curves.

Installation

npm install pumpfun-toolkit

Dependencies

This module requires the following dependencies:

  • @coral-xyz/anchor: Anchor framework for Solana
  • @solana/web3.js: Solana Web3.js library
  • @solana/spl-token: SPL Token library
  • pumpdotfun-sdk: PumpFun SDK
  • bn.js: Big Number library

Quick Start

import { PumpFunTrader, PumpFunConfig } from 'pumpfun-toolkit';
import { Connection, Keypair, PublicKey } from '@solana/web3.js';

// Initialize connection and keypair
const connection = new Connection('https://api.mainnet-beta.solana.com');
const keypair = Keypair.generate(); // Use your actual keypair

// Configure the PumpFun trader
const config: PumpFunConfig = {
  connection,
  programId: new PublicKey('PFundKqMyH5VuqKqkqQzqHqQqQqQqQqQqQqQqQqQqQq'),
  idl: {} // Your PumpFun IDL
};

const trader = new PumpFunTrader(config, keypair);

// Buy tokens
const buyResult = await trader.buy({
  mint: new PublicKey('token_mint_address'),
  amountAfterFee: 1.0, // SOL amount
  slippageBasisPoints: 500n // 5% slippage (optional)
});

// Sell tokens
const sellResult = await trader.sell({
  mint: new PublicKey('token_mint_address'),
  tokenBalance: 1000, // Token amount
  slippageBasisPoints: 500n // 5% slippage (optional)
});

API Reference

PumpFunTrader

The main class for interacting with the PumpFun protocol.

Constructor

constructor(config: PumpFunConfig, keypair: Keypair)
  • config: Configuration object containing connection, program ID, and IDL
  • keypair: Solana keypair for signing transactions

Methods

buy(params: BuyParams): Promise

Buy tokens using SOL.

Parameters:

  • mint: Token mint address
  • amountAfterFee: SOL amount to spend (after fees)
  • slippageBasisPoints: Slippage tolerance in basis points (default: 500n = 5%)

Returns:

  • transaction: Prepared transaction
  • estimatedAmount: Estimated token amount to receive
  • amountWithSlippage: Minimum token amount with slippage applied
sell(params: SellParams): Promise

Sell tokens for SOL.

Parameters:

  • mint: Token mint address
  • tokenBalance: Token amount to sell
  • slippageBasisPoints: Slippage tolerance in basis points (default: 500n = 5%)

Returns:

  • transaction: Prepared transaction
  • estimatedAmount: Estimated SOL amount to receive
  • amountWithSlippage: Minimum SOL amount with slippage applied

Utility Functions

calculateWithSlippageBuy(amount: bigint, basisPoints: bigint): bigint

Calculate buy amount with slippage applied.

calculateWithSlippageSell(amount: bigint, basisPoints: bigint): bigint

Calculate sell amount with slippage applied.

globalVolumeAccumulatorPda(): [PublicKey, number]

Get the global volume accumulator PDA.

userVolumeAccumulatorPda(user: PublicKey): [PublicKey, number]

Get the user volume accumulator PDA.

Constants

  • DEFAULT_SLIPPAGE_BASIS_POINTS: Default slippage of 500 basis points (5%)
  • PUMP_PROGRAM_ID: PumpFun program ID

Types

PumpFunConfig

interface PumpFunConfig {
  connection: Connection;
  programId: PublicKey;
  idl: any;
}

BuyParams

interface BuyParams {
  mint: PublicKey;
  amountAfterFee: number;
  slippageBasisPoints?: bigint;
}

SellParams

interface SellParams {
  mint: PublicKey;
  tokenBalance: number;
  slippageBasisPoints?: bigint;
}

TradingResult

interface TradingResult {
  transaction: Transaction;
  estimatedAmount: BN;
  amountWithSlippage: BN;
}

Example Usage

Complete Trading Example

import { PumpFunTrader, PumpFunConfig } from 'pumpfun-toolkit';
import { Connection, Keypair, PublicKey, sendAndConfirmTransaction } from '@solana/web3.js';

async function tradeExample() {
  // Setup
  const connection = new Connection('https://api.mainnet-beta.solana.com');
  const keypair = Keypair.generate(); // Use your actual keypair
  
  const config: PumpFunConfig = {
    connection,
    programId: new PublicKey('PFundKqMyH5VuqKqkqQzqHqQqQqQqQqQqQqQqQqQqQq'),
    idl: {} // Your PumpFun IDL
  };
  
  const trader = new PumpFunTrader(config, keypair);
  const tokenMint = new PublicKey('your_token_mint_address');
  
  try {
    // Buy tokens
    console.log('Buying tokens...');
    const buyResult = await trader.buy({
      mint: tokenMint,
      amountAfterFee: 0.1, // 0.1 SOL
      slippageBasisPoints: 300n // 3% slippage
    });
    
    // Send buy transaction
    const buySignature = await sendAndConfirmTransaction(
      connection,
      buyResult.transaction,
      [keypair]
    );
    console.log('Buy transaction confirmed:', buySignature);
    
    // Sell tokens
    console.log('Selling tokens...');
    const sellResult = await trader.sell({
      mint: tokenMint,
      tokenBalance: 1000, // Token amount
      slippageBasisPoints: 300n // 3% slippage
    });
    
    // Send sell transaction
    const sellSignature = await sendAndConfirmTransaction(
      connection,
      sellResult.transaction,
      [keypair]
    );
    console.log('Sell transaction confirmed:', sellSignature);
    
  } catch (error) {
    console.error('Trading error:', error);
  }
}

tradeExample();

Error Handling

The module throws descriptive errors for common issues:

  • Bonding curve account not found: When the token doesn't have a bonding curve
  • Transaction errors: When there are issues with transaction creation or execution

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

ISC