pub struct PumpDotFunSdk {
pub rpc: Arc<RpcClient>,
}Fields§
§rpc: Arc<RpcClient>Implementations§
Source§impl PumpDotFunSdk
impl PumpDotFunSdk
Sourcepub fn new(rpc: Arc<RpcClient>) -> Self
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}Sourcepub fn create(&self, accounts: CreateAccounts, args: CreateArgs) -> Instruction
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}Sourcepub fn buy(
&self,
accounts: BuyAccounts,
args: Buy,
) -> Result<Vec<Instruction>, ErrorCode>
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}Sourcepub fn sell(
&self,
accounts: SellAccounts,
args: Sell,
) -> Result<Vec<Instruction>, ErrorCode>
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§
impl !RefUnwindSafe for PumpDotFunSdk
impl !UnwindSafe for PumpDotFunSdk
impl Freeze for PumpDotFunSdk
impl Send for PumpDotFunSdk
impl Sync for PumpDotFunSdk
impl Unpin for PumpDotFunSdk
impl UnsafeUnpin for PumpDotFunSdk
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
Mutably borrows from an owned value. Read more
impl<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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 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> ⓘ
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