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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pump-trading

v3.0.0

Published

Official package to create, buy, and sell tokens on pump.fun (V1) with enhanced features

Readme

pump-trading

Official package to create, buy, and sell tokens on pump.fun (V1) easily

npm i pump-trading

Usage

This package provides a comprehensive API for interacting with the pump.fun platform for creating and trading tokens.

Get mint reserves, estimate the swap, create instructions, sign, and send.

const Pumpfun = require('pump-trading')
const SOL = require('like-solana')

const rpc = new SOL.RPC()
const pumpfun = new Pumpfun(rpc)

main()

async function main () {
  const mint = 'ExpuTKRK7sqfekMU74wUQM5SZf4WooyWEKabRwa126TG'
  const recentBlockhash = (await rpc.getLatestBlockhash()).blockhash
  const user = new SOL.Keypair('<secret key...>')

  // Buy 0.1 SOL of tokens with 3% slippage
  const reserves = await pumpfun.getReserves(mint)
  const swapBuy = pumpfun.quoteToBase(0.1, reserves, 0.03)
  const ixBuy = pumpfun.buy(mint, swapBuy.baseAmountOut, swapBuy.quoteInMax, user.publicKey, reserves)
  const txBuy = SOL.sign(ixBuy, { unitPrice: 0.0001, signers: [user], recentBlockhash })

  console.log('Buy signature:', SOL.signature(txBuy))

  await rpc.sendTransaction(txBuy)

  // ... (could wait for confirmation)
  await new Promise(resolve => setTimeout(resolve, 5000))

  // Sell the tokens we bought with 3% slippage
  const reserves2 = await pumpfun.getReserves(mint)
  const swapSell = pumpfun.baseToQuote(swapBuy.baseAmountOut, reserves2, 0.03)
  const ixSell = pumpfun.sell(mint, swapSell.baseAmountIn, swapSell.quoteOutMin, user.publicKey, reserves)
  const txSell = SOL.sign(ixSell, { unitPrice: 0.0001, signers: [user], recentBlockhash })

  console.log('Sell signature:', SOL.signature(txSell))

  await rpc.sendTransaction(txSell)

  // ...
}
// ... (like the code from before)
const fs = require('fs')

const mintKeyPair = new SOL.Keypair()
const mint = mintKeyPair.publicKey

const info = {
  name: '1337',
  symbol: '1337',
  description: '',
  image: fs.readFileSync('./logo.png'),
  website: '',
  telegram: '',
  twitter: ''
}

const uri = await pumpfun.createMetadata(info)
const ixCreate = pumpfun.create({ info, uri, mint }, user.publicKey)

// (Buying is optional)
const reserves = Pumpfun.initialReserves({ creator: user.publicKey })
const swapBuy = pumpfun.quoteToBase(0.1, reserves)
const ixBuy = pumpfun.buy(mint, swapBuy.baseAmountOut, swapBuy.quoteInMax, user.publicKey, reserves)

const txCreate = SOL.sign([...ixCreate, ...ixBuy], { unitPrice: 0.0001, signers: [user, mintKeyPair], recentBlockhash })

console.log('Mint', mint.toBase58())
console.log('Create hash', SOL.signature(txCreate))

await rpc.sendTransaction(txCreate)

API

pumpfun = new Pumpfun(rpc)

Create a new Pumpfun instance.

A solana-rpc instance must be provided.

reserves = await pumpfun.getReserves(mint)

Fetch the bonding curve as reserves.

Returns:

{
  virtualTokenReserves: BigInt,
  virtualSolReserves: BigInt,
  realTokenReserves: BigInt,
  realSolReserves: BigInt,
  tokenTotalSupply: BigInt,
  complete: Boolean,
  creator: String // Base58 public key
}

Buy

swap = pumpfun.quoteToBase(quoteAmountIn, reserves[, slippage, options])

Buy estimation on how many tokens you will receive based on quote (SOL).

Slippage is zero by default, you expect to receive what you estimated or more.

// 0.5 SOL to TOKENS at 3% slippage (Auto-converted to BigInt)
const swapBuy = pumpfun.quoteToBase(0.5, reserves, 0.03)

// BigInt(0.5 * 1e9) to TOKENS (Nine decimals)
const swapBuy = pumpfun.quoteToBase(500000000n, reserves, 0.03)

Options:

{
  sync: Boolean // For multiple continuous swaps
}

Returns:

{
  baseAmountOut: BigInt,
  quoteAmountIn: BigInt,
  userQuoteAmountIn: BigInt,
  quoteInMax: BigInt
}

ix = pumpfun.buy(mint, baseAmountOut, quoteInMax, userPublicKey, reserves)

Create buy instructions.

Note: Reserves here specifically only needs { creator }.

Sell

swap = pumpfun.baseToQuote(baseAmountIn, reserves[, slippage, options])

Sell estimation on how much SOL you will receive based on base (tokens).

Slippage is zero by default, you expect to receive what you estimated or more.

// 350000000 TOKENS to SOL at 3% slippage (Auto-converted to BigInt)
const swapSell = pumpfun.baseToQuote(350000000, reserves, 0.03)

// BigInt(350000000 * 1e6) to TOKENS (Six decimals)
const swapSell = pumpfun.baseToQuote(350000000000000n, reserves, 0.03)

Options:

{
  sync: Boolean // For multiple continuous swaps
}

Returns:

{
  baseAmountIn: BigInt,
  quoteAmountOut: BigInt,
  userQuoteAmountOut: BigInt,
  quoteOutMin: BigInt
}

ix = pumpfun.sell(mint, baseAmountIn, quoteOutMin, userPublicKey, reserves)

Create sell instructions.

Note: Reserves here specifically only needs { creator }.

Create

uri = await pumpfun.createMetadata(options)

Create an IPFS link to the metadata.

Options:

{
  name: String,
  symbol: String,
  image: Buffer,
  description: String, // Optional
  website: String, // Optional
  telegram: String, // Optional
  twitter: String // Optional
}

ix = pumpfun.create(options, userPublicKey)

Create instructions for making a token.

Options:

{
  mint: String, // Public key of the token
  name: String, // You would use the same from the metadata
  symbol: String, // Same
  uri: String // metadataUri (IPFS)
}

API (static)

reserves = Pumpfun.initialReserves(options)

Creates the initial reserves for a new token.

Options:

{
  creator: String
}

Returns:

{
  virtualTokenReserves: 1073000000000000n,
  virtualSolReserves: 30000000000n,
  realTokenReserves: 793100000000000n,
  realSolReserves: 0n,
  tokenTotalSupply: 1000000000000000n,
  complete: false,
  creator: String // From the options
}

Pumpfun.PROGRAM_ID

Indicates the program ID: 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P

progress = Pumpfun.progress(reserves)

Calculates the bonding curve completion in the floating range from 0 to 1.

marketCap = Pumpfun.marketCap(reserves)

Calculates the market capitalization of the token.

price = Pumpfun.price(reserves)

Calculates the price of 1 token in SOL (lamport units).

bondingCurve = Pumpfun.getBondingCurve(mint)

Returns the bonding curve address based on the mint public key.

metadataAddress = Pumpfun.getMetadataAddress(mint)

Returns the Metaplex / Metadata address based on the mint public key.

config = Pumpfun.global()

Returns the global config (authorities, fees, reserves, etcetera).

For Developers

This is the official pump.fun package for token operations. Here are some key implementation details:

Transaction Structure

The transaction structure follows the standard Solana model, with instructions created for various operations like buying, selling, and creating tokens.

Fee Structure

In addition to the standard protocol fees (returned in the global config), this package implements the official pumpfun fee to help maintain and improve the platform. All fees are processed on-chain for maximum security and transparency.

Address Handling

We automatically derive the correct program addresses for all operations, including bonding curves, metadata accounts, and associated token accounts.

Optimizations

  • BigInt is used for all numerical values to avoid precision issues with large numbers
  • Transaction instructions are batched where appropriate for efficiency
  • Reserve calculations are optimized to minimize computational overhead

Testing

The package includes comprehensive tests to verify functionality:

  • Basic creation, buying, and selling
  • Multi-user transactions
  • Offline swap calculations
  • Progress and market cap calculations
  • Fee processing verification

License

MIT