Pump.fun SDK for Rust
A Rust SDK for interacting with pump.fun on Solana devnet. This SDK provides easy-to-use functions for creating tokens, buying from bonding curves, and selling to bonding curves.
Features
- 🪙 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 Information
- Devnet Program ID:
6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P - Network: Solana Devnet
- Framework: Anchor
Installation
Add this SDK to your Cargo.toml:
[]
= { = "." }
= "2.3.4"
= "2.3.1"
Quick Start
1. Initialize the SDK
use Arc;
use PumpDotFunSdk;
use RpcClient;
let rpc_client = new;
let sdk = new;
2. Create a new token
use ;
use ;
let mint_keypair = new;
let user_keypair = new; // Your wallet keypair
let create_accounts = CreateAccounts ;
let create_args = CreateArgs ;
let instruction = sdk.create;
3. Buy tokens
use ;
use LAMPORTS_PER_SOL;
let buy_accounts = BuyAccounts ;
let buy_args = Buy ;
let instructions = sdk.buy?;
4. Sell tokens
use ;
let sell_accounts = SellAccounts ;
let sell_args = Sell ;
let instructions = sdk.sell?;
Running the Example
This repository includes a comprehensive example that demonstrates all SDK features.
Quick Setup (Recommended)
Run the setup script to automatically configure everything:
# Make sure you have Rust installed first
|
# Clone and run setup
The setup script will:
- Install Solana CLI (if needed)
- Configure devnet
- Create a wallet (if needed)
- Fund it with SOL
- Show you next steps
Manual Prerequisites
If you prefer manual setup:
-
Install Rust and Cargo:
| -
Install Solana CLI:
-
Get devnet SOL:
# Generate a new keypair (or use existing one) # Airdrop SOL to your wallet
Running the Example
-
Clone and build:
-
Run the examples:
Simple Example (recommended for beginners):
Full Example (comprehensive demonstration):
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).
SDK Structure
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
Key Concepts
Bonding Curves
pump.fun uses bonding curves to automatically provide liquidity for newly created tokens. As more tokens are bought, the price increases along the curve.
Slippage Protection
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 in basis points (500 = 5%)
Associated Token Accounts
The SDK automatically handles Associated Token Account (ATA) creation when needed for buy operations.
Error Handling
The SDK includes comprehensive error handling:
use ErrorCode;
match sdk.buy
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Testing
Run the test suite:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
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.
Support
For questions and support:
- Create an issue in this repository
- Check the Solana documentation
- Visit the Anchor documentation
Roadmap
- Mainnet support
- Additional slippage calculation methods
- Bulk operations support
- Event listening utilities
- Price calculation helpers
- Integration with popular Solana wallets