Struct PumpFun

Source
pub struct PumpFun {
    pub payer: Arc<Keypair>,
    pub rpc: Arc<RpcClient>,
    pub cluster: Cluster,
}
Expand description

Main client for interacting with the Pump.fun program

This struct provides the primary interface for interacting with the Pump.fun token platform on Solana. It handles connection to the Solana network and provides methods for token creation, buying, and selling using bonding curves.

§Examples

use pumpfun::{PumpFun, common::types::{Cluster, PriorityFee}};
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
use std::sync::Arc;

// Create a new client connected to devnet
let payer = Arc::new(Keypair::new());
let commitment = CommitmentConfig::confirmed();
let priority_fee = PriorityFee::default();
let cluster = Cluster::devnet(commitment, priority_fee);
let client = PumpFun::new(payer, cluster);

Fields§

§payer: Arc<Keypair>

Keypair used to sign transactions

§rpc: Arc<RpcClient>

RPC client for Solana network requests

§cluster: Cluster

Cluster configuration

Implementations§

Source§

impl PumpFun

Source

pub fn new(payer: Arc<Keypair>, cluster: Cluster) -> Self

Creates a new PumpFun client instance

Initializes a new client for interacting with the Pump.fun program on Solana. This client manages connection to the Solana network and provides methods for creating, buying, and selling tokens.

§Arguments
  • payer - Keypair used to sign and pay for transactions
  • cluster - Solana cluster configuration including RPC endpoints and transaction parameters
§Returns

Returns a new PumpFun client instance configured with the provided parameters

§Examples
use pumpfun::{PumpFun, common::types::{Cluster, PriorityFee}};
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
use std::sync::Arc;

let payer = Arc::new(Keypair::new());
let commitment = CommitmentConfig::confirmed();
let priority_fee = PriorityFee::default();
let cluster = Cluster::devnet(commitment, priority_fee);
let client = PumpFun::new(payer, cluster);
Source

pub async fn create( &self, mint: Keypair, metadata: CreateTokenMetadata, priority_fee: Option<PriorityFee>, ) -> Result<Signature, ClientError>

Creates a new token with metadata by uploading metadata to IPFS and initializing on-chain accounts

This method handles the complete process of creating a new token on Pump.fun:

  1. Uploads token metadata and image to IPFS
  2. Creates a new SPL token with the provided mint keypair
  3. Initializes the bonding curve that determines token pricing
  4. Sets up metadata using the Metaplex standard
§Arguments
  • mint - Keypair for the new token mint account that will be created
  • metadata - Token metadata including name, symbol, description and image file
  • priority_fee - Optional priority fee configuration for compute units. If None, uses the default from the cluster configuration
§Returns

Returns the transaction signature if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • Metadata upload to IPFS fails
  • Transaction creation fails
  • Transaction execution on Solana fails
§Examples
let mint = Keypair::new();
let metadata = CreateTokenMetadata {
    name: "My Token".to_string(),
    symbol: "MYTKN".to_string(),
    description: "A test token created with Pump.fun".to_string(),
    file: "path/to/image.png".to_string(),
    twitter: None,
    telegram: None,
    website: Some("https://example.com".to_string()),
};

let signature = client.create(mint, metadata, None).await?;
println!("Token created! Signature: {}", signature);
Source

pub async fn create_and_buy( &self, mint: Keypair, metadata: CreateTokenMetadata, amount_sol: u64, slippage_basis_points: Option<u64>, priority_fee: Option<PriorityFee>, ) -> Result<Signature, ClientError>

Creates a new token and immediately buys an initial amount in a single atomic transaction

This method combines token creation and an initial purchase into a single atomic transaction. This is often preferred for new token launches as it:

  1. Creates the token and its bonding curve
  2. Makes an initial purchase to establish liquidity
  3. Guarantees that the creator becomes the first holder

The entire operation is executed as a single transaction, ensuring atomicity.

§Arguments
  • mint - Keypair for the new token mint account that will be created
  • metadata - Token metadata including name, symbol, description and image file
  • amount_sol - Amount of SOL to spend on the initial buy, in lamports (1 SOL = 1,000,000,000 lamports)
  • slippage_basis_points - Optional maximum acceptable slippage in basis points (1 bp = 0.01%). If None, defaults to 500 (5%)
  • priority_fee - Optional priority fee configuration for compute units. If None, uses the default from the cluster configuration
§Returns

Returns the transaction signature if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • Metadata upload to IPFS fails
  • Account retrieval fails
  • Transaction creation fails
  • Transaction execution on Solana fails
§Examples
let mint = Keypair::new();
let metadata = CreateTokenMetadata {
    name: "My Token".to_string(),
    symbol: "MYTKN".to_string(),
    description: "A test token created with Pump.fun".to_string(),
    file: "path/to/image.png".to_string(),
    twitter: None,
    telegram: None,
    website: Some("https://example.com".to_string()),
};

// Create token and buy 0.1 SOL worth with 5% slippage tolerance
let amount_sol = sol_to_lamports(0.1f64); // 0.1 SOL in lamports
let slippage_bps = Some(500); // 5%

let signature = client.create_and_buy(mint, metadata, amount_sol, slippage_bps, None).await?;
println!("Token created and bought! Signature: {}", signature);
Source

pub async fn buy( &self, mint: Pubkey, amount_sol: u64, slippage_basis_points: Option<u64>, priority_fee: Option<PriorityFee>, ) -> Result<Signature, ClientError>

Buys tokens from a bonding curve by spending SOL

This method purchases tokens from a bonding curve by providing SOL. The amount of tokens received is determined by the bonding curve formula for the specific token. As more tokens are purchased, the price increases according to the curve function.

The method:

  1. Calculates how many tokens will be received for the given SOL amount
  2. Creates an associated token account for the buyer if needed
  3. Executes the buy transaction with slippage protection

A portion of the SOL is taken as a fee according to the global configuration.

§Arguments
  • mint - Public key of the token mint to buy
  • amount_sol - Amount of SOL to spend, in lamports (1 SOL = 1,000,000,000 lamports)
  • slippage_basis_points - Optional maximum acceptable slippage in basis points (1 bp = 0.01%). If None, defaults to 500 (5%)
  • priority_fee - Optional priority fee configuration for compute units. If None, uses the default from the cluster configuration
§Returns

Returns the transaction signature if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • The bonding curve account cannot be found
  • The buy price calculation fails
  • Transaction creation fails
  • Transaction execution on Solana fails
§Examples
let token_mint = pubkey!("SoMeTokenM1ntAddr3ssXXXXXXXXXXXXXXXXXXXXXXX");

// Buy 0.01 SOL worth of tokens with 3% max slippage
let amount_sol = sol_to_lamports(0.01f64); // 0.01 SOL in lamports
let slippage_bps = Some(300); // 3%

let signature = client.buy(token_mint, amount_sol, slippage_bps, None).await?;
println!("Tokens purchased! Signature: {}", signature);
Source

pub async fn sell( &self, mint: Pubkey, amount_token: Option<u64>, slippage_basis_points: Option<u64>, priority_fee: Option<PriorityFee>, ) -> Result<Signature, ClientError>

Sells tokens back to the bonding curve in exchange for SOL

This method sells tokens back to the bonding curve, receiving SOL in return. The amount of SOL received is determined by the bonding curve formula for the specific token. As more tokens are sold, the price decreases according to the curve function.

The method:

  1. Determines how many tokens to sell (all tokens or a specific amount)
  2. Calculates how much SOL will be received for the tokens
  3. Executes the sell transaction with slippage protection

A portion of the SOL is taken as a fee according to the global configuration.

§Arguments
  • mint - Public key of the token mint to sell
  • amount_token - Optional amount of tokens to sell in base units. If None, sells the entire balance
  • slippage_basis_points - Optional maximum acceptable slippage in basis points (1 bp = 0.01%). If None, defaults to 500 (5%)
  • priority_fee - Optional priority fee configuration for compute units. If None, uses the default from the cluster configuration
§Returns

Returns the transaction signature if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • The token account cannot be found
  • The bonding curve account cannot be found
  • The sell price calculation fails
  • Transaction creation fails
  • Transaction execution on Solana fails
§Examples
let token_mint = pubkey!("SoMeTokenM1ntAddr3ssXXXXXXXXXXXXXXXXXXXXXXX");

// Sell 1000 tokens with 2% max slippage
let amount_tokens = Some(1000);
let slippage_bps = Some(200); // 2%

let signature = client.sell(token_mint, amount_tokens, slippage_bps, None).await?;
println!("Tokens sold! Signature: {}", signature);

// Or sell all tokens with default slippage (5%)
let signature = client.sell(token_mint, None, None, None).await?;
println!("All tokens sold! Signature: {}", signature);
Source

pub async fn subscribe<F>( &self, commitment: Option<CommitmentConfig>, callback: F, ) -> Result<Subscription, ClientError>

Subscribes to real-time events from the Pump.fun program

This method establishes a WebSocket connection to the Solana cluster and subscribes to program log events from the Pump.fun program. It parses the emitted events into structured data types and delivers them through the provided callback function.

Event types include:

  • CreateEvent: Emitted when a new token is created
  • TradeEvent: Emitted when tokens are bought or sold
  • CompleteEvent: Emitted when a bonding curve operation completes
  • SetParamsEvent: Emitted when global parameters are updated
§Arguments
  • commitment - Optional commitment level for the subscription. If None, uses the default from the cluster configuration
  • callback - A function that will be called for each event with the following parameters:
    • signature: The transaction signature as a String
    • event: The parsed PumpFunEvent if successful, or None if parsing failed
    • error: Any error that occurred during parsing, or None if successful
    • response: The complete RPC logs response for additional context
§Returns

Returns a Subscription object that manages the lifecycle of the subscription. When this object is dropped, the subscription is automatically terminated. If the subscription cannot be established, returns a ClientError.

§Errors

Returns an error if:

  • The WebSocket connection cannot be established
  • The subscription request fails
§Examples
// Subscribe to token events
let subscription = client.subscribe(None, |signature, event, error, _| {
    match event {
        Some(pumpfun::common::stream::PumpFunEvent::Create(create_event)) => {
            println!("New token created: {} ({})", create_event.name, create_event.symbol);
            println!("Mint address: {}", create_event.mint);
        },
        Some(pumpfun::common::stream::PumpFunEvent::Trade(trade_event)) => {
            let action = if trade_event.is_buy { "bought" } else { "sold" };
            println!(
                "User {} {} {} tokens for {} SOL",
                trade_event.user,
                action,
                trade_event.token_amount,
                trade_event.sol_amount as f64 / 1_000_000_000.0
            );
        },
        Some(event) => println!("Other event received: {:#?}", event),
        None => {
            if let Some(err) = error {
                eprintln!("Error parsing event in tx {}: {}", signature, err);
            }
        }
    }
}).await?;

// Keep the subscription active
// When no longer needed, drop the subscription to unsubscribe
Source

pub fn get_priority_fee_instructions( priority_fee: &PriorityFee, ) -> Vec<Instruction>

Creates compute budget instructions for priority fees

Generates Solana compute budget instructions based on the provided priority fee configuration. These instructions are used to set the maximum compute units a transaction can consume and the price per compute unit, which helps prioritize transaction processing during network congestion.

§Arguments
  • priority_fee - Priority fee configuration containing optional unit limit and unit price
§Returns

Returns a vector of instructions to set compute budget parameters, which can be empty if no priority fee parameters are provided

§Examples
// Set both compute unit limit and price
let priority_fee = PriorityFee {
    unit_limit: Some(200_000),
    unit_price: Some(1_000), // 1000 micro-lamports per compute unit
};

let compute_instructions: Vec<Instruction> = PumpFun::get_priority_fee_instructions(&priority_fee);
Source

pub fn get_create_instruction( &self, mint: &Keypair, ipfs: TokenMetadataResponse, ) -> Instruction

Creates an instruction for initializing a new token

Generates a Solana instruction to create a new token with a bonding curve on Pump.fun. This instruction will initialize the token mint, metadata, and bonding curve accounts.

§Arguments
  • mint - Keypair for the new token mint account that will be created
  • ipfs - Token metadata response from IPFS upload containing name, symbol, and URI
§Returns

Returns a Solana instruction for creating a new token

§Examples
let mint = Keypair::new();
let metadata_response = utils::create_token_metadata(
    utils::CreateTokenMetadata {
        name: "Example Token".to_string(),
        symbol: "EXTKN".to_string(),
        description: "An example token".to_string(),
        file: "path/to/image.png".to_string(),
        twitter: None,
        telegram: None,
        website: None,
    }
).await?;

let create_instruction = client.get_create_instruction(&mint, metadata_response);
Source

pub async fn get_buy_instructions( &self, mint: Pubkey, amount_sol: u64, slippage_basis_points: Option<u64>, ) -> Result<Vec<Instruction>, ClientError>

Generates instructions for buying tokens from a bonding curve

Creates a set of Solana instructions needed to purchase tokens using SOL. These instructions may include creating an associated token account if needed, and the actual buy instruction with slippage protection.

§Arguments
  • mint - Public key of the token mint to buy
  • amount_sol - Amount of SOL to spend, in lamports (1 SOL = 1,000,000,000 lamports)
  • slippage_basis_points - Optional maximum acceptable slippage in basis points (1 bp = 0.01%). If None, defaults to 500 (5%)
§Returns

Returns a vector of Solana instructions if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • The global account or bonding curve account cannot be fetched
  • The buy price calculation fails
  • Token account-related operations fail
§Examples
let mint = pubkey!("TokenM1ntPubk3yXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
let amount_sol = sol_to_lamports(0.01); // 0.01 SOL
let slippage_bps = Some(300); // 3%

let buy_instructions = client.get_buy_instructions(mint, amount_sol, slippage_bps).await?;
Source

pub async fn get_sell_instructions( &self, mint: Pubkey, amount_token: Option<u64>, slippage_basis_points: Option<u64>, ) -> Result<Vec<Instruction>, ClientError>

Generates instructions for selling tokens back to a bonding curve

Creates a set of Solana instructions needed to sell tokens in exchange for SOL. These instructions include the sell instruction with slippage protection and may include closing the associated token account if all tokens are being sold and the feature is enabled.

§Arguments
  • mint - Public key of the token mint to sell
  • amount_token - Optional amount of tokens to sell in base units. If None, sells the entire balance
  • slippage_basis_points - Optional maximum acceptable slippage in basis points (1 bp = 0.01%). If None, defaults to 500 (5%)
§Returns

Returns a vector of Solana instructions if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • The token account or token balance cannot be fetched
  • The global account or bonding curve account cannot be fetched
  • The sell price calculation fails
  • Token account closing operations fail (when applicable)
§Examples
let mint = pubkey!("TokenM1ntPubk3yXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
let amount_tokens = Some(1000); // Sell 1000 tokens
let slippage_bps = Some(200); // 2%

let sell_instructions = client.get_sell_instructions(mint, amount_tokens, slippage_bps).await?;

// Or to sell all tokens:
let sell_all_instructions = client.get_sell_instructions(mint, None, None).await?;
Source

pub fn get_global_pda() -> Pubkey

Gets the Program Derived Address (PDA) for the global state account

Derives the address of the global state account using the program ID and a constant seed. The global state account contains program-wide configuration such as fee settings and fee recipient.

§Returns

Returns the PDA public key derived from the GLOBAL_SEED

§Examples
let global_pda: Pubkey = PumpFun::get_global_pda();
println!("Global state account: {}", global_pda);
Source

pub fn get_mint_authority_pda() -> Pubkey

Gets the Program Derived Address (PDA) for the mint authority

Derives the address of the mint authority PDA using the program ID and a constant seed. The mint authority PDA is the authority that can mint new tokens for any token created through the Pump.fun program.

§Returns

Returns the PDA public key derived from the MINT_AUTHORITY_SEED

§Examples
let mint_authority: Pubkey = PumpFun::get_mint_authority_pda();
println!("Mint authority account: {}", mint_authority);
Source

pub fn get_bonding_curve_pda(mint: &Pubkey) -> Option<Pubkey>

Gets the Program Derived Address (PDA) for a token’s bonding curve account

Derives the address of a token’s bonding curve account using the program ID, a constant seed, and the token mint address. The bonding curve account stores the state and parameters that govern the token’s price dynamics.

§Arguments
  • mint - Public key of the token mint
§Returns

Returns Some(PDA) if derivation succeeds, or None if it fails

§Examples
let mint = pubkey!("TokenM1ntPubk3yXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
if let Some(bonding_curve) = PumpFun::get_bonding_curve_pda(&mint) {
    println!("Bonding curve account: {}", bonding_curve);
}
Source

pub fn get_metadata_pda(mint: &Pubkey) -> Pubkey

Gets the Program Derived Address (PDA) for a token’s metadata account

Derives the address of a token’s metadata account following the Metaplex Token Metadata standard. The metadata account stores information about the token such as name, symbol, and URI pointing to additional metadata.

§Arguments
  • mint - Public key of the token mint
§Returns

Returns the PDA public key for the token’s metadata account

§Examples
let mint = pubkey!("TokenM1ntPubk3yXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
let metadata_pda = PumpFun::get_metadata_pda(&mint);
println!("Token metadata account: {}", metadata_pda);
Source

pub async fn get_global_account(&self) -> Result<GlobalAccount, ClientError>

Gets the global state account data containing program-wide configuration

Fetches and deserializes the global state account which contains program-wide configuration parameters such as:

  • Fee basis points for trading
  • Fee recipient account
  • Bonding curve parameters
  • Other platform-wide settings
§Returns

Returns the deserialized GlobalAccount if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • The account cannot be found on-chain
  • The account data cannot be properly deserialized
§Examples
let global = client.get_global_account().await?;
println!("Fee basis points: {}", global.fee_basis_points);
println!("Fee recipient: {}", global.fee_recipient);
Source

pub async fn get_bonding_curve_account( &self, mint: &Pubkey, ) -> Result<BondingCurveAccount, ClientError>

Gets a token’s bonding curve account data containing pricing parameters

Fetches and deserializes a token’s bonding curve account which contains the state and parameters that determine the token’s price dynamics, including:

  • Current supply
  • Reserve balance
  • Bonding curve parameters
  • Other token-specific configuration
§Arguments
  • mint - Public key of the token mint
§Returns

Returns the deserialized BondingCurveAccount if successful, or a ClientError if the operation fails

§Errors

Returns an error if:

  • The bonding curve PDA cannot be derived
  • The account cannot be found on-chain
  • The account data cannot be properly deserialized
§Examples
let mint = pubkey!("TokenM1ntPubk3yXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
let bonding_curve = client.get_bonding_curve_account(&mint).await?;
println!("Bonding Curve Account: {:#?}", bonding_curve);
Source

pub fn get_creator_vault_pda(creator: &Pubkey) -> Option<Pubkey>

Gets the creator vault address (for claiming pump creator fees)

Derives the token creator’s vault using the program ID, a constant seed, and the creator’s address.

§Arguments
  • creator - Public key of the token’s creator
§Returns

Returns Some(PDA) if derivation succeeds, or None if it fails

§Examples
let creator = pubkey!("Amya8kr2bzEY9kyXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
if let Some(bonding_curve) = PumpFun::get_creator_vault_pda(&creator) {
    println!("Creator vault address: {}", creator);
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,