Latest version of Pump.fun API. Easy to use, full version
npm install solana-pumpfun-apiLatest version of Pump.fun API. Easy to use, full version.
Join to follow updates: https://discord.gg/u955DwU8
- 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
``bash`
npm install solana-pumpfun-api
This library provides functions to interact with the Pump.fun protocol on Solana, specifically for buying, selling tokens, and getting current prices.
The buy function creates a versioned transaction for buying tokens from a Pump.fun bonding curve.
`typescript
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);
`
The sell function creates a versioned transaction for selling tokens back to the Pump.fun bonding curve.
`typescript
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);
`
The getAmount function calculates the number of tokens you can buy with a given amount of SOL, accounting for slippage.
`typescript
import { getAmount } from 'solana-pumpfun-api';
const tokenAmount = await getAmount('TOKEN_MINT_ADDRESS', 0.1, connection);
console.log(Tokens for 0.1 SOL: ${tokenAmount});`
The getSol function calculates the SOL you will receive for selling a given number of tokens, accounting for slippage.
`typescript
import { getSol } from 'solana-pumpfun-api';
const solAmount = await getSol('TOKEN_MINT_ADDRESS', 1000000, connection);
console.log(SOL for 1 token: ${solAmount});`
The buy function creates a versioned transaction for buying tokens from a Pump.fun bonding curve.
`typescript
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)
`
`typescript`
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).
The createIpfs function uploads metadata to IPFS for token creation.
`typescript
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://...',
});
`
The createCoin function creates a new token on Pump.fun, returning a transaction and mint address.
`typescript
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
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});``
https://github.com/backshade/solana-pumpfun-api