A production-ready Node.js application for automatically buying and selling tokens via PancakeSwap (BSC) and Jupiter (Solana).
- ✅ BSC Integration: Buy/sell tokens using PancakeSwap
- ✅ Solana Integration: Buy/sell tokens using Jupiter DEX aggregator
- ✅ Transaction Signing: Real blockchain transaction execution
- ✅ Slippage Protection: 5% slippage tolerance
- ✅ Error Handling: Comprehensive error management
- ✅ Production Ready: Proper logging, validation, and security
- Node.js 18+
- npm or yarn
- BSC wallet with BNB for gas fees
- Solana wallet with SOL for gas fees
- Clone the repository:
git clone <repository-url>
cd token-auto-buy- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env- Configure your environment variables in
.env:
# BSC Configuration
WALLET_PRIVATE_KEY=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
BSC_RPC_URL=https://bsc-dataseed.binance.org
# Solana Configuration
SOLANA_PRIVATE_KEY=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64]
SOLANA_RPC_URL=https://api.mainnet-beta.solana.comnpm run dev # Development mode
npm run build && npm start # Production modePOST /api/trade
Request body:
{
"amount": "0.1",
"type": "buy",
"contractAddress": "0x1234567890abcdef1234567890abcdef12345678",
"network": "BSC",
"recipient": "0x1234567890abcdef1234567890abcdef12345678"
}Response:
{
"success": true,
"message": "Trade executed successfully",
"data": {
"hash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"status": "success"
}
}- BSC: Binance Smart Chain using PancakeSwap
- SOLANA: Solana using Jupiter DEX aggregator
- Buy: Purchase tokens with native currency (BNB/SOL)
- Sell: Sell tokens for native currency (BNB/SOL)
BSC_RPC_URL=https://data-seed-prebsc-1-s1.binance.org:8545
BSC_CHAIN_ID=97
PANCAKESWAP_ROUTER=0xD99D1c33F9fC3444f8101754aBC46c52416550D1SOLANA_RPC_URL=https://api.devnet.solana.com- BSC Testnet: BSC Testnet Faucet
- Solana Devnet: Solana Faucet
- ✅ Private key validation
- ✅ Address validation
- ✅ Amount validation
- ✅ Slippage protection (5%)
- ✅ Gas limit protection
- ✅ Transaction confirmation
- ✅ Comprehensive error handling
The application includes comprehensive error handling for:
- Invalid wallet configuration
- Insufficient balances
- Network errors
- Transaction failures
- Invalid addresses
- Invalid amounts
src/
├── config/ # Network configurations
├── controllers/ # API controllers
├── helpers/ # Utility functions
├── middleware/ # Express middleware
├── routes/ # API routes
├── services/ # Trading services
├── types/ # TypeScript types
└── validators/ # Input validation
npm run buildnpm test- Set
NODE_ENV=productionin your environment - Use a secure RPC provider
- Ensure proper wallet security
- Monitor gas fees and slippage
- Set up proper logging and monitoring
ISC