A Rust SDK for interacting with pump.fun on Solana. This SDK provides easy-to-use functions for creating tokens, buying from bonding curves, and selling to bonding curves.
- πͺ Create new tokens with metadata and bonding curves
- π° Buy tokens from bonding curves with slippage protection
- πΈ Sell tokens to bonding curves with slippage protection
- π§ Built-in utilities for account management and PDA derivation
- β Type-safe Rust implementation using Anchor framework
- Program ID:
6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
- Network: Solana Mainnet
- Framework: Anchor
use std::sync::Arc;
use pumpdotfun_sdk::PumpDotFunSdk;
use solana_client::rpc_client::RpcClient;
let rpc_client = Arc::new(RpcClient::new("https://api.devnet.solana.com".to_string()));
let sdk = PumpDotFunSdk::new(rpc_client);
use pumpdotfun_sdk::instructions::create::{CreateAccounts, CreateArgs};
use solana_sdk::{signature::Keypair, signer::Signer};
let mint_keypair = Keypair::new();
let user_keypair = Keypair::new(); // Your wallet keypair
let create_accounts = CreateAccounts {
mint: mint_keypair.pubkey(),
user: user_keypair.pubkey(),
};
let create_args = CreateArgs {
name: "My Token".to_string(),
symbol: "TOKEN".to_string(),
uri: "https://example.com/metadata.json".to_string(),
creator: user_keypair.pubkey(),
};
let instruction = sdk.create(create_accounts, create_args);
use pumpdotfun_sdk::instructions::buy::{BuyAccounts, Buy};
use solana_sdk::native_token::LAMPORTS_PER_SOL;
let buy_accounts = BuyAccounts {
mint: mint_pubkey,
user: user_keypair.pubkey(),
};
let buy_args = Buy {
amount: 100_000_000, // Amount of tokens to buy
max_sol_cost: LAMPORTS_PER_SOL / 1000, // Maximum 0.001 SOL
slippage: 10, // 10% slippage tolerance
};
let instructions = sdk.buy(buy_accounts, buy_args)?;
use pumpdotfun_sdk::instructions::sell::{SellAccounts, Sell};
let sell_accounts = SellAccounts {
mint: mint_pubkey,
user: user_keypair.pubkey(),
};
let sell_args = Sell {
amount: 50_000_000, // 0.05 tokens (assuming 9 decimals)
min_sol_output: LAMPORTS_PER_SOL / 1000000,
slippage: 10, // 10% slippage
};
let instructions = sdk.sell(sell_accounts, sell_args)?;
This repository includes a comprehensive example that demonstrates all SDK features.
Run the setup script to automatically configure everything:
# Make sure you have Rust installed first
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Clone and run setup
git clone <your-repo>
cd pumpdotfun-sdk
./scripts/setup.sh
The setup script will:
- Install Solana CLI (if needed)
- Configure devnet
- Create a wallet (if needed)
- Fund it with SOL
- Show you next steps
If you prefer manual setup:
-
Install Rust and Cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Install Solana CLI:
sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)"
-
Get devnet SOL:
# Generate a new keypair (or use existing one) solana-keygen new --outfile ~/.config/solana/devnet-wallet.json # Airdrop SOL to your wallet solana airdrop 2 --url devnet --keypair ~/.config/solana/devnet-wallet.json
-
Clone and build:
git clone <your-repo> cd pumpdotfun-sdk cargo build
-
Run the examples:
Simple Example (recommended for beginners):
cargo run --bin simple_example
The examples will:
- Connect to Solana devnet
- Create a new token with bonding curve
- Buy tokens from the bonding curve
- Sell some tokens back (full example only)
- Display transaction signatures and results
Note: The simple example uses your actual wallet from
~/.config/solana/devnet-wallet.json
, while the full example generates a new keypair each time (which won't have SOL).
src/
βββ lib.rs # Main SDK entry point
βββ instructions/ # Instruction builders
β βββ create.rs # Token creation
β βββ buy.rs # Token purchasing
β βββ sell.rs # Token selling
βββ constants.rs # Program constants
βββ errors.rs # Error definitions
βββ pda.rs # PDA derivation utilities
βββ states/ # Account state definitions
βββ global.rs # Global state structure
pump.fun uses bonding curves to automatically provide liquidity for newly created tokens. As more tokens are bought, the price increases along the curve.
Both buy and sell operations include slippage protection:
- Buy: Specify maximum SOL you're willing to spend
- Sell: Specify minimum SOL you're willing to receive
- Slippage: Tolerance (5 = 5%)
The SDK automatically handles Associated Token Account (ATA) creation when needed for buy operations.
The SDK includes comprehensive error handling:
use pumpdotfun_sdk::errors::ErrorCode;
match sdk.buy(accounts, args) {
Ok(instructions) => {
// Handle success
}
Err(ErrorCode::InvalidSlippage) => {
println!("Slippage must be non-negative");
}
Err(ErrorCode::GlobalNotFound) => {
println!("Global state not found - program may not be initialized");
}
Err(e) => {
println!("Other error: {:?}", e);
}
}
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This SDK is for educational and development purposes. Always test thoroughly on devnet before using on mainnet. The authors are not responsible for any financial losses.