๐ PumpFun Swap SDK Integration Guide - cryptoking-max/solana-sniper-bot GitHub Wiki
This guide explains how to use the PumpSdk to execute buy and sell transactions on Pump.fun via Solana using custom logic.
-
Solana RPC endpoint
-
Private key loaded into wallet
-
@pump-fun/pump-sdkinstalled -
ENV variables:
-
BUY_SLIPPAGE_BPS_PERCENTAGE(default: 500) -
SELL_SLIPPAGE_BPS_PERCENTAGE(default: 500) -
BUY_PRIORITIZATION_FEE_LAMPORTS(default: 2000n) -
SELL_PRIORITIZATION_FEE_LAMPORTS(default: 2000n)
-
export async function buy_pumpfun(mint: string, amount: number): Promise<string>- Load the wallet and initialize the SDK.
- Fetch global and bonding curve data.
- Compute
token_amountusinggetBuyTokenAmountFromSolAmount. - Construct buy instructions using the SDK.
- Add compute unit price/limit for better priority.
- Send and confirm the transaction.
await buy_pumpfun("MintAddressHere", 0.1);export async function sell_pumpfun(mint: string, token_amount: number): Promise<string>- Retry logic up to 3 times in case of failure.
- Validate if the wallet has enough tokens to sell.
- Fetch bonding curve data and calculate
sol_amount. - Build sell instructions using the SDK.
- Append compute budget instructions.
- Submit and confirm the transaction.
await sell_pumpfun("MintAddressHere", 1000);Used to increase priority of transactions.
ComputeBudgetProgram.setComputeUnitLimit({ units: 200000 });
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: prioritizationFee });- Retries up to 3 times for
sell_pumpfun - Logs errors and dynamically adjusts sell amount based on current balance
- Gracefully exits if no balance is found
/src
|- swap.ts # Contains buy_pumpfun & sell_pumpfun
|- wallet.ts # loadwallet()
|- utils.ts # parseBigIntEnv(), transactionFromInstructions()
.env
README.md
- Use devnet first by setting your Solana RPC
- Use low SOL and test tokens to validate swap logic
- Monitor logs to confirm transaction status