๐ Setup Guide - Ethereum MEV Arbitrage Bot
October 13, 2025 ยท View on GitHub
Table of Contents
- Prerequisites
- Installation
- Configuration
- Smart Contract Deployment
- Running the Bot
- Testing
- Troubleshooting
- Security Best Practices
Prerequisites
System Requirements
- Operating System: Linux (Ubuntu 20.04+), macOS, or Windows 10+
- RAM: Minimum 4GB, Recommended 8GB+
- Storage: 20GB+ free space
- Network: Stable internet connection with low latency
Software Requirements
- Node.js: v16.0.0 or higher
- npm: v7.0.0 or higher
- Git: Latest version
Knowledge Requirements
- Basic understanding of Ethereum and DeFi
- Familiarity with command line interface
- Understanding of JavaScript/Node.js
- Knowledge of smart contracts (Solidity)
Installation
Step 1: Clone the Repository
git clone https://github.com/devstorm2576916/ethereum-mev-bot.git
cd ethereum-mev-bot
Step 2: Install Dependencies
# Install Node.js dependencies
npm install
# Or using Yarn
yarn install
Step 3: Install Hardhat (for smart contract deployment)
npm install --save-dev hardhat
Step 4: Create Required Directories
mkdir -p logs
mkdir -p data
Configuration
Step 1: Create Environment File
Copy the example environment file:
cp .env.example .env
Step 2: Configure Environment Variables
Edit .env file with your settings:
# Network Configuration
ETHEREUM_RPC_URL=https://mainnet.infura.io/v3/YOUR_INFURA_KEY
ETHEREUM_WSS_URL=wss://mainnet.infura.io/ws/v3/YOUR_INFURA_KEY
CHAIN_ID=1
# Wallet Configuration
PRIVATE_KEY=your_private_key_here_without_0x_prefix
WALLET_ADDRESS=0xYourWalletAddress
# Bot Configuration
MIN_PROFIT_THRESHOLD=0.01 # Minimum profit in ETH
MAX_GAS_PRICE=100 # Maximum gas price in gwei
SLIPPAGE_TOLERANCE=0.5 # Slippage tolerance in %
CHECK_INTERVAL=1000 # Check interval in milliseconds
MAX_TRADE_SIZE=10 # Maximum trade size in ETH
ENABLE_MEMPOOL_MONITORING=false # Enable mempool monitoring
# Telegram Bot (Optional)
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Logging
ENABLE_LOGGING=true
LOG_LEVEL=info # debug, info, warn, error
Step 3: Obtain Required API Keys
Infura (or Alchemy)
- Go to Infura or Alchemy
- Create a free account
- Create a new project
- Copy the API key and WebSocket URL
Telegram Bot (Optional)
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow the instructions to create your bot
- Copy the bot token
To get your Chat ID:
- Search for
@userinfoboton Telegram - Start a chat
- It will send you your Chat ID
Step 4: Fund Your Wallet
Your wallet needs ETH for gas fees:
Recommended: 0.5 - 1.0 ETH for gas fees
โ ๏ธ Warning:
- NEVER share your private key
- Use a separate wallet for the bot
- Don't store large amounts in the bot wallet
Smart Contract Deployment
Step 1: Compile Contracts
npx hardhat compile
Expected output:
Compiled 5 Solidity files successfully
Step 2: Test Contracts (Optional but Recommended)
npx hardhat test
Step 3: Deploy to Testnet (Recommended First)
Update hardhat.config.js to use Goerli or Sepolia testnet:
npx hardhat run scripts/deploy.js --network goerli
Step 4: Deploy to Mainnet
โ ๏ธ Warning: Ensure you have enough ETH for deployment gas fees (~0.05-0.1 ETH)
npx hardhat run scripts/deploy.js --network mainnet
Expected output:
๐ Deploying FlashloanArbitrage contract...
๐ Deploying with account: 0x...
๐ฐ Account balance: ...
โ
FlashloanArbitrage deployed to: 0x...
๐ Add this to your .env file:
ARBITRAGE_CONTRACT_ADDRESS=0x...
Step 5: Update Environment Variables
Add the deployed contract address to your .env file:
ARBITRAGE_CONTRACT_ADDRESS=0xYourDeployedContractAddress
Step 6: Verify Contract on Etherscan (Optional)
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS \
AAVE_ADDRESS_PROVIDER \
UNISWAP_V2_ROUTER \
SUSHISWAP_ROUTER \
UNISWAP_V3_ROUTER
Running the Bot
Option 1: Production Mode
npm start
Option 2: Development Mode (with auto-reload)
npm run dev
Option 3: Using PM2 (Recommended for 24/7 operation)
Install PM2:
npm install -g pm2
Start the bot:
pm2 start src/index.js --name "mev-bot"
Monitor:
pm2 monit
View logs:
pm2 logs mev-bot
Stop:
pm2 stop mev-bot
Restart:
pm2 restart mev-bot
Testing
Test on Hardhat Network (Local Blockchain)
- Start local Hardhat node with mainnet fork:
npx hardhat node
- In a new terminal, run the bot:
npm start
Test on Testnet
- Configure testnet in
.env:
ETHEREUM_RPC_URL=https://goerli.infura.io/v3/YOUR_INFURA_KEY
ETHEREUM_WSS_URL=wss://goerli.infura.io/ws/v3/YOUR_INFURA_KEY
CHAIN_ID=5
-
Get testnet ETH from faucets:
-
Run the bot:
npm start
Dry Run Mode (Simulation)
You can modify the code to run in simulation mode:
// In src/bot/ArbitrageBot.js
const DRY_RUN = true; // Don't execute real trades
if (!DRY_RUN) {
await this.executeArbitrage(opportunity);
} else {
logger.info('DRY RUN: Would execute arbitrage', opportunity);
}
Monitoring
View Logs
Real-time logs:
tail -f logs/combined.log
Error logs:
tail -f logs/error.log
Trade logs:
tail -f logs/trades.log
Telegram Notifications
If configured, you'll receive notifications for:
- โ Bot started
- ๐ Opportunities found
- โ Successful trades
- โ Failed trades
- ๐ Hourly statistics
- ๐ Daily summaries
Troubleshooting
Common Issues
1. "Cannot connect to Ethereum network"
Solution:
- Check your RPC URL is correct
- Verify your internet connection
- Try a different RPC provider (Alchemy, Infura, Quicknode)
2. "Insufficient funds for gas"
Solution:
- Check your wallet balance:
await wallet.getBalance() - Send more ETH to your wallet
3. "Transaction underpriced"
Solution:
- Increase
MAX_GAS_PRICEin.env - The network is congested, wait or increase gas price
4. "No arbitrage opportunities found"
Solution:
- This is normal - opportunities are rare
- Lower
MIN_PROFIT_THRESHOLD(but be careful!) - Add more tokens to watchlist
- Check market conditions (high volatility = more opportunities)
5. "Contract execution reverted"
Solution:
- The trade was not profitable after all
- Slippage was too high
- Check contract has sufficient allowances
6. "Rate limit exceeded"
Solution:
- You're making too many RPC calls
- Upgrade to paid Infura/Alchemy plan
- Increase cache timeout
- Reduce
CHECK_INTERVAL
Debug Mode
Enable debug logging:
LOG_LEVEL=debug npm start
Check Smart Contract
Verify contract is deployed correctly:
npx hardhat console --network mainnet
const contract = await ethers.getContractAt(
"FlashloanArbitrage",
"YOUR_CONTRACT_ADDRESS"
);
// Check owner
await contract.owner();
// Check balance
await contract.getBalance("TOKEN_ADDRESS");
Security Best Practices
1. Private Key Security
- โ NEVER commit
.envfile to Git - โ NEVER share your private key
- โ Use a dedicated wallet for the bot
- โ Consider using a hardware wallet for large amounts
- โ Regularly rotate keys
2. Smart Contract Security
- โ Audit your smart contracts before deployment
- โ Use established libraries (OpenZeppelin)
- โ Test extensively on testnet
- โ Start with small amounts
- โ Implement emergency withdraw function
3. Operational Security
- โ Run on a secure server (not your personal computer)
- โ Use a VPS with firewall configured
- โ Keep software updated
- โ Monitor logs for suspicious activity
- โ Set up alerts for unusual behavior
4. Financial Security
- โ Start with small amounts
- โ Set strict profit thresholds
- โ Implement stop-loss mechanisms
- โ Regularly withdraw profits
- โ Don't invest more than you can afford to lose
5. API Security
- โ Use environment variables for API keys
- โ Rotate API keys regularly
- โ Use rate-limited endpoints
- โ Monitor API usage
Performance Optimization
1. RPC Provider
Use a dedicated RPC provider with:
- Low latency (<50ms)
- High rate limits
- Archive node access (for historical data)
- WebSocket support
Recommended Providers:
- Alchemy - Free tier available
- Infura - Free tier available
- QuickNode - Paid, very fast
- Ankr - Free tier available
2. Server Location
Deploy the bot on a server close to Ethereum nodes:
- AWS us-east-1 (Virginia)
- AWS eu-west-1 (Ireland)
- Use a VPS with good network connectivity
3. Code Optimization
- Reduce RPC calls with caching
- Use batch requests where possible
- Optimize gas usage in smart contracts
- Use WebSocket for real-time data
4. Database (Optional)
For high-frequency trading, consider adding Redis for:
- Price caching
- Rate limiting
- Session management
Updating the Bot
Update Dependencies
npm update
Update Code
git pull origin main
npm install
Update Smart Contract
If the contract is updated:
- Deploy new contract
- Update
ARBITRAGE_CONTRACT_ADDRESSin.env - Withdraw funds from old contract
- Restart bot
Backup and Recovery
Backup Important Files
# Backup environment file (store securely!)
cp .env .env.backup
# Backup logs
tar -czf logs-backup-$(date +%Y%m%d).tar.gz logs/
# Backup configuration
cp -r config/ config-backup/
Recovery Procedure
If something goes wrong:
-
Stop the bot:
pm2 stop mev-bot -
Check contract funds:
npx hardhat console --network mainnet -
Emergency withdraw:
const contract = await ethers.getContractAt("FlashloanArbitrage", "ADDRESS"); await contract.emergencyWithdraw("TOKEN_ADDRESS"); -
Check logs:
cat logs/error.log -
Restore from backup if needed
Next Steps
After successful setup:
- โ Test on testnet thoroughly
- โ Start with small amounts on mainnet
- โ Monitor performance for 24-48 hours
- โ Optimize parameters based on results
- โ Gradually increase position sizes
- โ Review and improve strategy
Support
- ๐ง Email: support@yourdomain.com
- ๐ฌ Telegram: @YourTelegramUsername
- ๐ Issues: GitHub Issues
- ๐ Documentation: Full Docs
โ ๏ธ Disclaimer: This bot is for educational purposes. Trading cryptocurrency involves substantial risk of loss. Use at your own risk.