This guide explains how to build a Solana trading bot that replicates transactions from a specified wallet using Pump.fun API and Yellowstone gRPC.
Educational Purpose Only
This guide is for educational purposes only and should not be considered financial advice. Trading bots carry risks and may result in financial losses. Always conduct your own research and consult a financial advisor before using trading bots or engaging in trading activities.
Overview
We'll create a Solana trading bot that:
- Monitors specified wallets on Pump.fun DEX
- Replicates their buy transactions using predefined strategies
- Tests bot functionality through simulated transactions
Prerequisites
- Intermediate knowledge of Solana development and DeFi concepts
- JavaScript and Node.js experience
- Solana wallet with SOL balance
- QuickNode account with Yellowstone gRPC plugin enabled
Key Components
Pump.fun API
We'll use the /pump-fun/swap endpoint to:
- Get serialized transactions for swaps
- Requires wallet public key, transaction type, token mint address, and amount
Yellowstone gRPC
Yellowstone provides:
- Real-time event updates via gRPC API
- Custom subscriptions for blockchain monitoring
- Ideal for building trading bots and dApps
Project Setup
Initialize Node.js project:
npm init -y npm install @solana/web3.js@1 bs58 dotenv @triton-one/yellowstone-grpcConfigure
.envfile:SOLANA_RPC=<your_rpc_endpoint> SECRET_KEY=<your_wallet_secret_key> METIS_ENDPOINT=<your_metis_endpoint> YELLOWSTONE_ENDPOINT=<your_yellowstone_endpoint> YELLOWSTONE_TOKEN=<your_yellowstone_token>
Building the Trading Bot
Core Functions
fetchSwapTransaction()- Gets swap transaction from Pump.fun APIsignTransaction()- Signs transaction with wallet keypairsendAndConfirmTransaction()- Broadcasts signed transactionhandleWhaleBuy()- Processes copied transactions
Yellowstone Subscription
Configure subscription to:
- Monitor specified wallet addresses
- Filter Pump.fun program transactions
- Process buy/sell events
Transaction Processing
handleData = (data) => {
// Process transaction data
// Identify buy/sell transactions
// Extract token mint and amounts
// Trigger copy trades
};Testing the Bot
- Fund your bot wallet
Run the bot:
node bot.js- Execute test transactions from monitored wallet
- Verify bot responses and logs
Enhancements
Consider adding:
- Variable buy amounts based on transaction size
- Stop-loss/sell signals
- Multi-protocol monitoring
👉 Explore advanced bot configurations
FAQ
What's the minimum SOL needed per transaction?
The default minimum is 0.001 SOL, configurable in MIN_TX_AMOUNT.
Can I use TypeScript instead?
Yes! Check our TypeScript and Web3.js 2.0 guides for adaptation.
Is there rate limiting?
Public endpoints may have rate limits. For production use, consider dedicated endpoints.
How do I handle failed transactions?
The bot logs all transaction attempts with status information for debugging.
👉 Learn more about transaction handling
Key improvements:
1. Structured content with clear hierarchy
2. SEO-optimized headings and keywords
3. Removed sensitive/duplicate content
4. Added engaging anchor texts
5. Included FAQ section
6. Maintained professional yet accessible tone