๐Ÿ“˜ 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.


๐Ÿ“ฆ Prerequisites

  • Solana RPC endpoint

  • Private key loaded into wallet

  • @pump-fun/pump-sdk installed

  • 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)

๐Ÿ”„ Buy Function

export async function buy_pumpfun(mint: string, amount: number): Promise<string>

๐Ÿงฉ Steps:

  1. Load the wallet and initialize the SDK.
  2. Fetch global and bonding curve data.
  3. Compute token_amount using getBuyTokenAmountFromSolAmount.
  4. Construct buy instructions using the SDK.
  5. Add compute unit price/limit for better priority.
  6. Send and confirm the transaction.

โœ… Example:

await buy_pumpfun("MintAddressHere", 0.1);

๐Ÿ” Sell Function

export async function sell_pumpfun(mint: string, token_amount: number): Promise<string>

๐Ÿงฉ Steps:

  1. Retry logic up to 3 times in case of failure.
  2. Validate if the wallet has enough tokens to sell.
  3. Fetch bonding curve data and calculate sol_amount.
  4. Build sell instructions using the SDK.
  5. Append compute budget instructions.
  6. Submit and confirm the transaction.

โœ… Example:

await sell_pumpfun("MintAddressHere", 1000);

โš™๏ธ Compute Budget Setup

Used to increase priority of transactions.

ComputeBudgetProgram.setComputeUnitLimit({ units: 200000 });
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: prioritizationFee });

โš ๏ธ Error Handling

  • 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

๐Ÿ“ File Structure Example

/src
  |- swap.ts          # Contains buy_pumpfun & sell_pumpfun
  |- wallet.ts        # loadwallet()
  |- utils.ts         # parseBigIntEnv(), transactionFromInstructions()
.env
README.md

๐Ÿงช Testing Tips

  • Use devnet first by setting your Solana RPC
  • Use low SOL and test tokens to validate swap logic
  • Monitor logs to confirm transaction status

โš ๏ธ **GitHub.com Fallback** โš ๏ธ