A Solana program to interact with Pump.fun tokens through a router contract. This is an enhanced version of the original Pump.fun router (credit to DAO-Fun) with several improvements:
- Exact SOL Input: Unlike the original Pump.fun interface that requires token amount input, this router allows you to specify exact SOL amounts for buying tokens
- Enhanced Protection: Added slippage control and min/max token output parameters for buy operations
- Latest Pump.fun Features: Updated to support new Pump.fun program features (September 4, 2025):
- Creator vault integration
- Volume tracking
- Fee configuration
- Event authority
- Install dependencies:
# Install Solana CLI
curl --proto '=https' --tlsv1.2 -sSfL https://solana-install.solana.workers.dev | bash
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
# Install Anchor
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest
# Install project dependencies
npm install- Generate deployment wallet:
solana-keygen new -o payer.json- Configure RPC (Helius recommended for reliability):
# Option 1: Free Solana RPC (can be unstable)
solana config set --url mainnet-beta
# Option 2: Helius RPC (recommended - free up to 100k requests/day)
# Get your API key at https://helius.xyz
solana config set --url 'https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY'
# Don't forget !!
# Anchor.toml
[provider]
cluster = "https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY"
wallet = "./payer.json"# Generate new program keypair
solana-keygen new -o target/deploy/router-keypair.json --force
# Get program ID
solana address -k target/deploy/router-keypair.json
# Update program ID in Anchor.toml and lib.rs
anchor keys syncanchor build# Configure for mainnet
solana config set --url mainnet-beta
# Update Anchor.toml with your RPC if needed
# [provider]
# cluster = "mainnet"
# wallet = "./payer.json"
# Deploy
anchor deployIf you need to close the program and recover the rent:
# Get program ID
PROGRAM_ID=$(solana address -k target/deploy/router-keypair.json)
# Close program and recover SOL
solana program close $PROGRAM_ID --url mainnet-beta --keypair payer.json --bypass-warningThe project includes a trading script to interact with Pump.fun tokens through the router.
Edit scripts/trade.ts and modify the CONFIG section:
const CONFIG = {
// Your RPC endpoint
RPC_URL: 'https://your-rpc-endpoint.com',
// Path to your wallet
WALLET_PATH: './payer.json',
// Token to trade
TOKEN_MINT: 'token-address',
TOKEN_CREATOR: 'creator-address',
// Trade settings
BUY_AMOUNT_SOL: 0.001, // Amount to buy in SOL
SELL_PERCENTAGE: 100, // % of balance to sell
SLIPPAGE: 5, // Max slippage %
MIN_TOKENS: 0, // Min tokens to receive
MAX_TOKENS: 10_000_000, // Max tokens to receive
TOKEN_DECIMALS: 6, // Token decimals
};Buy tokens:
ts-node scripts/trade.ts buySell tokens:
ts-node scripts/trade.ts sell- Always backup your
payer.jsonandrouter-keypair.json - Test with small amounts first
- Verify token addresses before trading
- Use a reliable RPC endpoint
- Mainnet deployment: ~2 SOL (recoverable via program close)
- Transaction fees: ~0.00001 SOL per tx
# Check program ID
solana address -k target/deploy/router-keypair.json
# Check program status
solana program show $(solana address -k target/deploy/router-keypair.json)
# Check wallet balance
solana balance -k payer.json
# Close program and recover SOL
solana program close $(solana address -k target/deploy/router-keypair.json) \
--url mainnet-beta \
--keypair payer.json \
--bypass-warningIf your deployment fails, your SOL may remain stuck in "buffer" accounts. Here's how to recover them:
# Get a free API key at https://helius.xyz
solana config set --url 'https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY'# List all buffers containing your SOL
solana program show --buffers# For each buffer found, close the account to recover SOL
solana program close BUFFER_ADDRESS --keypair payer.json --bypass-warning
# Example:
# solana program close 9tRqNh6Aqt7tyNNvb96JozBbZUx4oSANHAcSZrdu5ub8 --keypair payer.json --bypass-warning# Check your new balance
solana balance -k payer.json
# Confirm no more buffers exist
solana program show --buffers- RPC Issues: Use a premium RPC like Helius to avoid timeouts
- Stuck SOL: Follow the "Recovering Stuck SOL" section above
- Insufficient Balance: Make sure your wallet has enough SOL
- Transaction Errors: Check slippage settings and token addresses
- ATA Errors: The script will automatically create ATAs if needed
- Program Close Fails: Make sure you're using the correct keypair and network