Pumpfun Object

The Pumpfun global object and methods.

Pumpfun Object Documentation

The Pumpfun class provides methods to interact with the Pump.fun decentralized trading service on the Solana blockchain. It supports watching for pool creation and trade events, as well as buying and selling tokens. This class extends the Subscribable class, enabling subscription to Pump.fun-related events.

Methods

watchCreatePools

Description Watches for the creation of new liquidity pools on Pump.fun and invokes a callback when an event occurs.

Signature

public async watchCreatePools(
  callback: (event: PumpfunCreatePool) => void
): Promise<SubscriptionResult>

Parameters

  • callback ((event: PumpfunCreatePool) => void): The callback function to handle pool creation events.

Returns

  • Promise<SubscriptionResult>: The result of the subscription operation.

Example Usage

pumpfun.watchCreatePools((event) => {
  console.log("New pool created:", event);
});

watchTrades

Description Watches for trade events (buy or sell) on Pump.fun and invokes a callback when a trade occurs.

Signature

public async watchTrades(
  callback: (event: PumpfunTrade) => void
): Promise<SubscriptionResult>

Parameters

  • callback ((event: PumpfunTrade) => void): The callback function to handle trade events.

Returns

  • Promise<SubscriptionResult>: The result of the subscription operation.

Example Usage

pumpfun.watchTrades((event) => {
  console.log("Trade event:", event);
});

buyTokens

Description Buys tokens on Pump.fun by specifying the mint address, amount of SOL, slippage tolerance, and an optional priority fee.

Signature

public async buyTokens({
  mint,
  amount,
  slippage,
  priorityFee,
  createATA,
}: PumpfunBuyRequest): Promise<Transaction>

Parameters

  • mint (PublicKeyOrString): The mint address of the token to buy.

  • amount (string | number): The amount of SOL to spend.

  • slippage (number): Optional. The slippage tolerance (in percentage).

  • priorityFee (string | number): Optional. The priority fee in lamports for faster transaction processing.

  • createATA (boolean): Optional. Whether to create an associated token account. Default is true.

Returns

  • Promise<Transaction>: The deserialized transaction object representing the buy operation.

Example Usage

const buyTx = await pumpfun.buyTokens({
  mint: "TokenMintAddress",
  amount: 1, // 1 SOL
  slippage: 0.5, // 0.5% slippage tolerance
  priorityFee: 10000, // 10,000 lamports priority fee
});
console.log("Buy transaction:", buyTx);

sellTokens

Description Sells tokens on Pump.fun by specifying the mint address and the amount of tokens to sell.

Signature

public async sellTokens({
  mint,
  amount,
}: PumpfunSellRequest): Promise<Transaction>

Parameters

  • mint (PublicKeyOrString): The mint address of the token to sell.

  • amount (string | number): The amount of tokens to sell.

Returns

  • Promise<Transaction>: The deserialized transaction object representing the sell operation.

Example Usage

const sellTx = await pumpfun.sellTokens({
  mint: "TokenMintAddress",
  amount: 1000, // Amount of tokens to sell
});
console.log("Sell transaction:", sellTx);

Types

Trade

Represents a trade event (buy or sell).

type Trade = {
  side: "buy" | "sell";
  mint: string;
  user: string;
  sol: {
    amount: string;
    uiAmount: string;
  };
  token: {
    amount: string;
    decimals?: number;
    uiAmount?: string;
  };
};

PumpfunBuyRequest

Request type for buying tokens on Pump.fun.

type PumpfunBuyRequest = {
  mint: PublicKeyOrString;
  amount: string | number;
  slippage?: number;
  priorityFee?: string | number;
  createATA?: boolean;
};

PumpfunSellRequest

Request type for selling tokens on Pump.fun.

type PumpfunSellRequest = {
  mint: PublicKeyOrString;
  amount: string | number;
};

PumpfunTrade

Represents a Pump.fun trade event.

type PumpfunTrade = {
  service: "pumpfun";
  event: "trade";
  transaction: VersionedTransactionResponse;
  trade: Trade;
};

PumpfunCreatePool

Represents a Pump.fun pool creation event.

type PumpfunCreatePool = {
  service: "pumpfun";
  event: "create-pool";
  transaction: VersionedTransactionResponse;
  pool?: {
    bondingCurve: string;
    associatedBondingCurve: string;
    user: string;
    mint: string;
    metadata: string;
  };
};

Last updated