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

solana-pumpfun-api

v0.2.12

Published

Latest version of Pump.fun API. Easy to use, full version

Readme

Solana Pump.fun API

Latest version of Pump.fun API. Easy to use, full version.

Join to follow updates: https://discord.gg/u955DwU8

Features

  • Buy&Sell tokens
  • Mint token
  • Set priority fee option
  • Cheepest and fastest transactions
  • Get current price
  • Calculate amount by SOL in liquidity pool
  • Calculate SOL by amount in liquidity pool
  • Cache Pump.fun HTTP api
  • Cache solana RPC requests

Installation

npm install solana-pumpfun-api

Usage

This library provides functions to interact with the Pump.fun protocol on Solana, specifically for buying, selling tokens, and getting current prices.

Buy Tokens

The buy function creates a versioned transaction for buying tokens from a Pump.fun bonding curve.

import { buy } from 'solana-pumpfun-api';
import { Connection, Keypair } from '@solana/web3.js';
import bs58 from 'bs58';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.fromSecretKey(bs58.decode('SECRET_KEY')); // Replace with your wallet
const address = 'TOKEN_MINT_ADDRESS';
const sol = 0.1;
const amount = await getAmount(sol, address);

const transaction = await buy({
  walletAddress: wallet.publicKey.toString(),
  address,
  sol,
  amount,
  connection,
});

transaction.sign([wallet])

const signature = await connection.sendTransaction(transaction);

Sell Tokens

The sell function creates a versioned transaction for selling tokens back to the Pump.fun bonding curve.

import { sell } from 'solana-pumpfun-api';
import { Connection, Keypair } from '@solana/web3.js';
import bs58 from 'bs58';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.fromSecretKey(bs58.decode('SECRET_KEY')); // Replace with your wallet
const address = 'TOKEN_MINT_ADDRESS';
const amount = 10000000;
const sol = await getSol(amount, address);

const transaction = await sell({
  walletAddress: wallet.publicKey.toString(),
  address,
  sol,
  amount,
  connection,
});

transaction.sign([wallet])

const signature = await connection.sendTransaction(transaction);

Get Amount by SOL

The getAmount function calculates the number of tokens you can buy with a given amount of SOL, accounting for slippage.

import { getAmount } from 'solana-pumpfun-api';

const tokenAmount = await getAmount('TOKEN_MINT_ADDRESS', 0.1, connection);
console.log(`Tokens for 0.1 SOL: ${tokenAmount}`);

Get SOL by Amount

The getSol function calculates the SOL you will receive for selling a given number of tokens, accounting for slippage.

import { getSol } from 'solana-pumpfun-api';

const solAmount = await getSol('TOKEN_MINT_ADDRESS', 1000000, connection);
console.log(`SOL for 1 token: ${solAmount}`);

Usage Example. Fastest version

The buy function creates a versioned transaction for buying tokens from a Pump.fun bonding curve.

import { buy, getAmount } from 'solana-pumpfun-api';
import { Connection, Keypair } from '@solana/web3.js';
import bs58 from 'bs58';
import sendTransaction from "solana-transaction-sender";

let withCreateAccount = true;

const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.fromSecretKey(bs58.decode('SECRET_KEY'));
const sol = 0.1;
const address = 'TOKEN_MINT_ADDRESS';
const amount = await getAmount(address, sol, connection);

const transaction = await buy({
  walletAddress: wallet.publicKey.toString(),
  address,
  sol,
  amount,
  connection,
  priorityFee: 0.001, // Prioritize your transaction
  withCreateAccount, // Create token account once to reduce fee
  tokenInfoRevalidate: 200_000, // Cache pump.fun http api in ms
});

// Disable account creation after the first transaction
withCreateAccount = false;
transaction.sign([wallet])

const signature = await sendTransaction(transaction, {
    connection,
    commitment: "processed", // Return status if solana leader got transaction
    maxAttempts: 30,
    repeatTimeout: 50, // Spam validator to get prioritized queue
    mode: "fast",
});

console.log('Transaction sent: https://solscan.io/tx/' + signature)

TradeOptions Interface

interface TradeOptions {
  walletAddress: string;
  address: string;
  amount: number;
  sol: number;
  connection: Connection;
  tokenInfoRevalidate?: number;
  withCreateAccount?: boolean;
  priorityFee?: number;
}
  • walletAddress: The public key of the wallet as a string.
  • address: The mint address of the token.
  • amount: The number of whole tokens to buy/sell (the instruction uses amount * 1_000_000 for 6-decimal tokens).
  • sol: For buy: max SOL to spend. For sell: min SOL to receive.
  • connection: Solana RPC connection.
  • tokenInfoRevalidate: Cache duration for token info in ms (default 60s).
  • withCreateAccount: Whether to include ATA creation (default: true).
  • priorityFee: Priority fee in SOL (default: 0).

Create IPFS Metadata

The createIpfs function uploads metadata to IPFS for token creation.

import { createIpfs } from 'solana-pumpfun-api';

const metadataUri = await createIpfs({
  image: new Blob([...]), // Your image blob
  name: 'My Token',
  symbol: 'MTK',
  description: 'Description',
  twitter: 'https://twitter.com/...',
  telegram: 'https://t.me/...',
  website: 'https://...',
});

Create Coin (Token)

The createCoin function creates a new token on Pump.fun, returning a transaction and mint address.

import { createCoin } from 'solana-pumpfun-api';
import { Connection, Keypair } from '@solana/web3.js';
import bs58 from 'bs58';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.fromSecretKey(bs58.decode('SECRET_KEY'));
async function imageUrlToBlob(url: string): Promise<Blob> {
    const response = await fetch(url);
    return await response.blob();
}
const blob = await imageUrlToBlob('https://pump.fun/logo.png')

const { transaction, mint } = await createCoin({
  walletAddress: wallet.publicKey.toString(),
  image: blob,
  name: 'My Token',
  symbol: 'MTK',
  description: 'Description',
  twitter: 'https://twitter.com/...',
  telegram: 'https://t.me/...',
  website: 'https://...',
  priorityFee: 0.001,
});

// Sign and send the transaction
transaction.sign([wallet]);
const signature = await connection.sendTransaction(transaction);
console.log(`Token created: ${mint}`);

Repository

https://github.com/backshade/solana-pumpfun-api