Skip to main content

PumpDotFunSdk

Struct PumpDotFunSdk 

Source
pub struct PumpDotFunSdk {
    pub rpc: Arc<RpcClient>,
}

Fields§

§rpc: Arc<RpcClient>

Implementations§

Source§

impl PumpDotFunSdk

Source

pub fn new(rpc: Arc<RpcClient>) -> Self

Examples found in repository?
examples/simple_example.rs (line 29)
24fn main() -> Result<(), Box<dyn std::error::Error>> {
25    println!("🚀 Simple pump.fun SDK Example");
26
27    // Connect to devnet
28    let rpc_client = Arc::new(RpcClient::new("https://api.devnet.solana.com".to_string()));
29    let sdk = PumpDotFunSdk::new(rpc_client.clone());
30
31    // Load your wallet (adjust path as needed)
32    let wallet_path = std::env::var("SOLANA_WALLET").unwrap_or_else(|_| {
33        let home = std::env::var("HOME").unwrap_or_else(|_| "/home/user".to_string());
34        format!("{}/.config/solana/devnet-wallet.json", home)
35    });
36
37    let user_keypair = match read_keypair_file(&wallet_path) {
38        Ok(keypair) => keypair,
39        Err(_) => {
40            println!("❌ Could not load wallet from {}", wallet_path);
41            println!(
42                "💡 Generate one with: solana-keygen new --outfile {}",
43                wallet_path
44            );
45            println!("💡 Fund it with: solana airdrop 2 --url devnet");
46            return Ok(());
47        }
48    };
49
50    println!("✅ Loaded wallet: {}", user_keypair.pubkey());
51
52    // Check balance
53    let balance = rpc_client.get_balance(&user_keypair.pubkey())?;
54    println!(
55        "💰 Balance: {:.4} SOL",
56        balance as f64 / LAMPORTS_PER_SOL as f64
57    );
58
59    if balance < LAMPORTS_PER_SOL / 10 {
60        println!("⚠️  Low balance! Run: solana airdrop 2 --url devnet");
61        return Ok(());
62    }
63
64    // Example: Create a new token
65    println!("\n📝 Creating a new token...");
66    let mint_pubkey = create_simple_token(&sdk, &user_keypair)?;
67
68    // Example: Buy some tokens
69    println!("\n💰 Buying tokens...");
70    buy_simple_tokens(&sdk, &user_keypair, &mint_pubkey)?;
71
72    println!("\n🎉 Simple example completed! Check the transactions on Solana Explorer (devnet)");
73
74    println!("\n💰 Selling tokens...");
75    sell_simple_tokens(&sdk, &user_keypair, &mint_pubkey)?;
76
77    Ok(())
78}
Source

pub fn create(&self, accounts: CreateAccounts, args: CreateArgs) -> Instruction

Examples found in repository?
examples/simple_example.rs (line 99)
80fn create_simple_token(
81    sdk: &PumpDotFunSdk,
82    user_keypair: &Keypair,
83) -> Result<Pubkey, Box<dyn std::error::Error>> {
84    let mint_keypair = Keypair::new();
85    let mint_pubkey = mint_keypair.pubkey();
86
87    let accounts = CreateAccounts {
88        mint: mint_pubkey,
89        user: user_keypair.pubkey(),
90    };
91
92    let args = CreateArgs {
93        name: "Test Pump Token".to_string(),
94        symbol: "TEST".to_string(),
95        uri: "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png".to_string(),
96        creator: user_keypair.pubkey(),
97    };
98
99    let instruction = sdk.create(accounts, args);
100    let recent_blockhash = sdk.rpc.get_latest_blockhash()?;
101
102    let mut transaction = Transaction::new_with_payer(&[instruction], Some(&user_keypair.pubkey()));
103    transaction.sign(&[user_keypair, &mint_keypair], recent_blockhash);
104
105    let signature = sdk.rpc.send_and_confirm_transaction(&transaction)?;
106    println!(
107        "✅ Token created! Mint: {} | TX: {}",
108        mint_pubkey, signature
109    );
110
111    Ok(mint_pubkey)
112}
Source

pub fn buy( &self, accounts: BuyAccounts, args: Buy, ) -> Result<Vec<Instruction>, ErrorCode>

Examples found in repository?
examples/simple_example.rs (line 131)
114fn buy_simple_tokens(
115    sdk: &PumpDotFunSdk,
116    user_keypair: &Keypair,
117    mint: &Pubkey,
118) -> Result<(), Box<dyn std::error::Error>> {
119    let accounts = BuyAccounts {
120        mint: *mint,
121        user: user_keypair.pubkey(),
122    };
123
124    let args = Buy {
125        amount: 100_000_000,                   // 0.1 tokens (assuming 9 decimals)
126        max_sol_cost: LAMPORTS_PER_SOL / 1000, // Max 0.001 SOL
127        slippage: 10,                          // 10% slippage
128    };
129
130    let instructions = sdk
131        .buy(accounts, args)
132        .map_err(|e| format!("Buy error: {:?}", e))?;
133    let recent_blockhash = sdk.rpc.get_latest_blockhash()?;
134
135    let mut transaction = Transaction::new_with_payer(&instructions, Some(&user_keypair.pubkey()));
136    transaction.sign(&[user_keypair], recent_blockhash);
137
138    let signature = sdk.rpc.send_and_confirm_transaction(&transaction)?;
139    println!("✅ Tokens purchased! TX: {}", signature);
140
141    Ok(())
142}
Source

pub fn sell( &self, accounts: SellAccounts, args: Sell, ) -> Result<Vec<Instruction>, ErrorCode>

Examples found in repository?
examples/simple_example.rs (line 161)
144fn sell_simple_tokens(
145    sdk: &PumpDotFunSdk,
146    user_keypair: &Keypair,
147    mint: &Pubkey,
148) -> Result<(), Box<dyn std::error::Error>> {
149    let accounts = SellAccounts {
150        mint: *mint,
151        user: user_keypair.pubkey(),
152    };
153
154    let args = Sell {
155        amount: 50_000_000,                         // 0.05 tokens (assuming 9 decimals)
156        min_sol_output: LAMPORTS_PER_SOL / 1000000, 
157        slippage: 10,                               // 10% slippage
158    };
159
160    let instructions = sdk
161        .sell(accounts, args)
162        .map_err(|e| format!("Sell error: {:?}", e))?;
163    let recent_blockhash = sdk.rpc.get_latest_blockhash()?;
164
165    let mut transaction = Transaction::new_with_payer(&instructions, Some(&user_keypair.pubkey()));
166    transaction.sign(&[user_keypair], recent_blockhash);
167
168    let signature = sdk.rpc.send_and_confirm_transaction(&transaction)?;
169    println!("✅ Tokens sold! TX: {}", signature);
170
171    Ok(())
172}

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> ErasedDestructor for T
where T: 'static,

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, 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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