A comprehensive Solana trading bot using rust language on Pumpfun, PumpSwap, RaydiumLaunchpad, Boopfun
- Multi-DEX Support: Trade on Pump.fun, PumpSwap, and other Solana DEXs
- Smart Transaction Routing: Multiple SWQoS (Solana Web Quality of Service) providers for optimal transaction submission
- Token Creation: Create and deploy new tokens with metadata on IPFS
- Priority Fees & MEV Protection: Built-in support for priority fees and MEV protection through Jito bundles
- Comprehensive Trading: Buy, sell, and create tokens with customizable slippage and fees
- Default RPC: Standard Solana RPC endpoints
- Jito: MEV protection and bundle submission
- NextBlock: High-performance transaction processing
- Blox: Advanced routing and execution
- ZeroSlot: Fast transaction confirmation
- Temporal: Time-based transaction optimization
cargo add solana-trading-sdk
use solana_trading_sdk::{
common::{TradingClient, TradingConfig},
swqos::SWQoSType,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = TradingClient::new(TradingConfig {
rpc_url: "https://solana-rpc.publicnode.com".to_string(),
swqos: vec![
SWQoSType::Default("https://solana-rpc.publicnode.com".to_string(), None),
SWQoSType::Jito("https://mainnet.block-engine.jito.wtf".to_string()),
],
})?;
client.initialize().await?;
Ok(())
}
use solana_trading_sdk::{
dex::types::DexType,
instruction::builder::PriorityFee,
};
use solana_sdk::{native_token::sol_to_lamports, pubkey::Pubkey, signature::Keypair};
async fn buy_token() -> anyhow::Result<()> {
let client = get_trading_client().await?;
let payer = Keypair::from_base58_string("your_private_key");
let mint = Pubkey::from_str("token_mint_address")?;
let sol_amount = sol_to_lamports(1.0); // 1 SOL
let slippage_basis_points = 3000; // 30%
let fee = PriorityFee {
unit_limit: 100000,
unit_price: 10000000,
};
let tip = sol_to_lamports(0.001); // 0.001 SOL tip
// Buy on Pump.fun
client.dexs[&DexType::Pumpfun]
.buy(&payer, &mint, sol_amount, slippage_basis_points, Some(fee), Some(tip))
.await?;
Ok(())
}
use solana_trading_sdk::{
ipfs::{metadata::create_token_metadata, types::CreateTokenMetadata},
dex::{pumpfun::Pumpfun, types::Create},
};
async fn create_token() -> anyhow::Result<()> {
// 1. Create metadata
let token_info = CreateTokenMetadata {
name: "My Token".to_string(),
symbol: "MTK".to_string(),
description: "A revolutionary new token".to_string(),
file: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==".to_string(),
twitter: Some("@mytoken".to_string()),
telegram: Some("@mytokengroup".to_string()),
website: Some("https://mytoken.com".to_string()),
metadata_uri: None,
};
let metadata = create_token_metadata(token_info, "your_pinata_jwt_token").await?;
// 2. Create token on Pump.fun
let payer = Keypair::from_base58_string("your_private_key");
let mint = Keypair::new();
let create = Create {
name: metadata.metadata.name,
symbol: metadata.metadata.symbol,
uri: metadata.metadata_uri,
mint: mint.pubkey(),
buy_sol_amount: Some(sol_to_lamports(0.1)),
slippage_basis_points: Some(3000),
};
let pumpfun_client = get_pumpfun_client().await?;
pumpfun_client.create(payer, create, Some(fee), Some(tip)).await?;
Ok(())
}
async fn transfer_sol() -> anyhow::Result<()> {
let from = Keypair::from_base58_string("sender_private_key");
let to = Pubkey::from_str("recipient_address")?;
let amount = sol_to_lamports(0.1); // 0.1 SOL
let swqos_client = get_swqos_client();
swqos_client.transfer(&from, &to, amount, Some(fee)).await?;
Ok(())
}
async fn transfer_token() -> anyhow::Result<()> {
let from = Keypair::from_base58_string("sender_private_key");
let to = Pubkey::from_str("recipient_address")?;
let mint = Pubkey::from_str("token_mint_address")?;
let amount = 1000; // Token amount in smallest units
let swqos_client = get_swqos_client();
swqos_client.spl_transfer(&from, &to, &mint, amount, Some(fee)).await?;
Ok(())
}
Configure multiple SWQoS providers for optimal transaction routing:
let swqos = vec![
SWQoSType::Default("https://solana-rpc.publicnode.com".to_string(), None),
SWQoSType::Jito("https://mainnet.block-engine.jito.wtf".to_string()),
SWQoSType::NextBlock("https://fra.nextblock.io".to_string(), "your_api_key".to_string()),
SWQoSType::Blox("https://fra.blox.so".to_string(), "your_api_key".to_string()),
SWQoSType::ZeroSlot("https://fra.zeroslot.io".to_string(), "your_api_key".to_string()),
SWQoSType::Temporal("https://fra.temporal.io".to_string(), "your_api_key".to_string()),
];
Set custom priority fees for faster transaction confirmation:
let fee = PriorityFee {
unit_limit: 100000, // Compute unit limit
unit_price: 10000000, // Micro-lamports per compute unit
};
Check the main.rs
file for complete working examples of:
- Setting up trading clients
- Buying and selling tokens
- Creating new tokens
- Transferring SOL and SPL tokens
- Using different SWQoS providers
TradingClient
- Main client for trading operationsTradingEndpoint
- RPC and SWQoS endpoint managementDexTrait
- Common interface for all DEX implementations
DefaultSWQoSClient
- Standard RPC clientJitoClient
- Jito MEV protectionNextBlockClient
- NextBlock routingBloxClient
- Blox executionZeroSlotClient
- ZeroSlot confirmationTemporalClient
- Temporal optimization
create_token_metadata
- Upload token metadata to IPFSCreateTokenMetadata
- Token metadata structure
- RPC Endpoint: Use a reliable Solana RPC endpoint
- Pinata JWT Token: Required for IPFS metadata uploads
- SWQoS API Keys: Optional API keys for premium routing services
The SDK uses anyhow::Result
for comprehensive error handling. All functions return detailed error information for debugging.
Contributions are welcome! Please feel free to 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. Trading cryptocurrencies involves risk of loss.