๐Ÿš€ Setup Guide - Ethereum MEV Arbitrage Bot

October 13, 2025 ยท View on GitHub

Table of Contents


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)

  1. Go to Infura or Alchemy
  2. Create a free account
  3. Create a new project
  4. Copy the API key and WebSocket URL

Telegram Bot (Optional)

  1. Open Telegram and search for @BotFather
  2. Send /newbot command
  3. Follow the instructions to create your bot
  4. Copy the bot token

To get your Chat ID:

  1. Search for @userinfobot on Telegram
  2. Start a chat
  3. 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
npx hardhat test

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

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)

  1. Start local Hardhat node with mainnet fork:
npx hardhat node
  1. In a new terminal, run the bot:
npm start

Test on Testnet

  1. 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
  1. Get testnet ETH from faucets:

  2. 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_PRICE in .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 .env file 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:

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:

  1. Deploy new contract
  2. Update ARBITRAGE_CONTRACT_ADDRESS in .env
  3. Withdraw funds from old contract
  4. 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:

  1. Stop the bot:

    pm2 stop mev-bot
    
  2. Check contract funds:

    npx hardhat console --network mainnet
    
  3. Emergency withdraw:

    const contract = await ethers.getContractAt("FlashloanArbitrage", "ADDRESS");
    await contract.emergencyWithdraw("TOKEN_ADDRESS");
    
  4. Check logs:

    cat logs/error.log
    
  5. Restore from backup if needed


Next Steps

After successful setup:

  1. โœ… Test on testnet thoroughly
  2. โœ… Start with small amounts on mainnet
  3. โœ… Monitor performance for 24-48 hours
  4. โœ… Optimize parameters based on results
  5. โœ… Gradually increase position sizes
  6. โœ… Review and improve strategy

Support


โš ๏ธ Disclaimer: This bot is for educational purposes. Trading cryptocurrency involves substantial risk of loss. Use at your own risk.