The PumpFun struct is the primary entry point for interacting with the program. It abstracts complex tasks like PDA management, transaction signing, and ATA management.
Key Capabilities:
- Automatic ATA Management: The SDK automatically creates Associated Token Accounts (ATAs) during buy transactions by default.
- Token Creation: Use
create or create_and_buy with CreateTokenMetadata to launch new tokens. - Trading: Use
buy and sell methods. sell includes slippage protection. - State Queries: Use
get_bonding_curve_account to fetch the current state of a token's bonding curve.
use pumpfun::{
accounts::BondingCurveAccount,
common::types::{Cluster, PriorityFee},
utils::CreateTokenMetadata,
PumpFun,
};
// ... imports for solana_sdk and std
// Initialize client
let payer = Arc::new(Keypair::new());
let client = PumpFun::new(
payer.clone(),
Cluster::localnet(CommitmentConfig::finalized(), PriorityFee::default()),
);
// Example: Create a token
let metadata = CreateTokenMetadata {
name: "Token Name".to_string(),
symbol: "TKN".to_string(),
description: "Description".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_keypair, metadata, fee).await.unwrap();
// Example: Buy tokens
let signature = client.buy(mint_pubkey, sol_amount, track_volume, None, fee).await.unwrap();
// Example: Sell tokens
let signature = client.sell(mint_pubkey, None, None, fee).await.unwrap();