| Crates.io | pumpdotfun-sdk |
| lib.rs | pumpdotfun-sdk |
| version | 0.1.2 |
| created_at | 2025-07-16 22:25:51.706358+00 |
| updated_at | 2025-07-16 22:59:58.893258+00 |
| description | Rust SDK for interacting with the pump.fun contract |
| homepage | https://github.com/mohitejaikumar/pumpdotfun-sdk |
| repository | https://github.com/mohitejaikumar/pumpdotfun-sdk |
| max_upload_size | |
| id | 1756723 |
| size | 261,583 |
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.
6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6Puse 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:
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:
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:
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.