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
impl PumpFun
Sourcepub fn new(payer: Arc<Keypair>, cluster: Cluster) -> Self
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 transactionscluster
- 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);
Sourcepub async fn create(
&self,
mint: Keypair,
metadata: CreateTokenMetadata,
priority_fee: Option<PriorityFee>,
) -> Result<Signature, ClientError>
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:
- Uploads token metadata and image to IPFS
- Creates a new SPL token with the provided mint keypair
- Initializes the bonding curve that determines token pricing
- Sets up metadata using the Metaplex standard
§Arguments
mint
- Keypair for the new token mint account that will be createdmetadata
- Token metadata including name, symbol, description and image filepriority_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);
Sourcepub 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>
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:
- Creates the token and its bonding curve
- Makes an initial purchase to establish liquidity
- 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 createdmetadata
- Token metadata including name, symbol, description and image fileamount_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);
Sourcepub async fn buy(
&self,
mint: Pubkey,
amount_sol: u64,
slippage_basis_points: Option<u64>,
priority_fee: Option<PriorityFee>,
) -> Result<Signature, ClientError>
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:
- Calculates how many tokens will be received for the given SOL amount
- Creates an associated token account for the buyer if needed
- 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 buyamount_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);
Sourcepub async fn sell(
&self,
mint: Pubkey,
amount_token: Option<u64>,
slippage_basis_points: Option<u64>,
priority_fee: Option<PriorityFee>,
) -> Result<Signature, ClientError>
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:
- Determines how many tokens to sell (all tokens or a specific amount)
- Calculates how much SOL will be received for the tokens
- 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 sellamount_token
- Optional amount of tokens to sell in base units. If None, sells the entire balanceslippage_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);
Sourcepub async fn subscribe<F>(
&self,
commitment: Option<CommitmentConfig>,
callback: F,
) -> Result<Subscription, ClientError>
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 createdTradeEvent
: Emitted when tokens are bought or soldCompleteEvent
: Emitted when a bonding curve operation completesSetParamsEvent
: Emitted when global parameters are updated
§Arguments
commitment
- Optional commitment level for the subscription. If None, uses the default from the cluster configurationcallback
- A function that will be called for each event with the following parameters:signature
: The transaction signature as a Stringevent
: The parsed PumpFunEvent if successful, or None if parsing failederror
: Any error that occurred during parsing, or None if successfulresponse
: 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
Sourcepub fn get_priority_fee_instructions(
priority_fee: &PriorityFee,
) -> Vec<Instruction>
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);
Sourcepub fn get_create_instruction(
&self,
mint: &Keypair,
ipfs: TokenMetadataResponse,
) -> Instruction
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 createdipfs
- 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);
Sourcepub async fn get_buy_instructions(
&self,
mint: Pubkey,
amount_sol: u64,
slippage_basis_points: Option<u64>,
) -> Result<Vec<Instruction>, ClientError>
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 buyamount_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?;
Sourcepub async fn get_sell_instructions(
&self,
mint: Pubkey,
amount_token: Option<u64>,
slippage_basis_points: Option<u64>,
) -> Result<Vec<Instruction>, ClientError>
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 sellamount_token
- Optional amount of tokens to sell in base units. If None, sells the entire balanceslippage_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?;
Sourcepub fn get_global_pda() -> Pubkey
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);
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);
Sourcepub fn get_bonding_curve_pda(mint: &Pubkey) -> Option<Pubkey>
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);
}
Sourcepub fn get_metadata_pda(mint: &Pubkey) -> Pubkey
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);
Sourcepub async fn get_global_account(&self) -> Result<GlobalAccount, ClientError>
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);
Sourcepub async fn get_bonding_curve_account(
&self,
mint: &Pubkey,
) -> Result<BondingCurveAccount, ClientError>
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);
Sourcepub fn get_creator_vault_pda(creator: &Pubkey) -> Option<Pubkey>
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§
impl Freeze for PumpFun
impl !RefUnwindSafe for PumpFun
impl Send for PumpFun
impl Sync for PumpFun
impl Unpin for PumpFun
impl !UnwindSafe for PumpFun
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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