- Introduction
- Features
- Project Structure
- Prerequisites
- Installation
- Configuration
- Deploying the Flashloan Contract
- Obtaining API Keys
- Running the Bot
- Strategies
- Logging
- Troubleshooting
- Contributing
- License
- Disclaimer
0xBuilder is an advanced Ethereum trading bot for high-frequency trading and MEV opportunities. It implements strategies like front-running, back-running, sandwich attacks, and flashloan executions using various DeFi protocols. The bot monitors the Ethereum mempool for arbitrage opportunities, executes transactions, and interacts with smart contracts.
It uses flashloans for capital efficiency and dynamic gas pricing optimal transaction fees. It is highly configurable, supports multiple wallets, tokens, and trading pairs, and provides detailed logging for analysis. It integrates with various APIs for blockchain and market data, enabling real-time market analysis and strategy execution. 0xBuilder is designed for traders, developers, and researchers looking to leverage MEV opportunities in the Ethereum ecosystem.
Note: 0xBuilder is a work in progress.
- Mempool Monitoring: Tracks the Ethereum mempool for arbitrage and profit opportunities
- Strategy Execution: Implements front-running, back-running, sandwich attacks, and flashloan executions
- Flashloan Integration: Utilizes flashloans for capital efficiency without initial capital
- Market Analysis: Analyzes market conditions using multiple APIs
- Dynamic Gas Pricing: Adjusts gas prices based on network conditions
- Nonce Management: Manages nonces to prevent transaction failures
- Safety Mechanisms: Includes safety checks to manage risks
- Transaction Bundling: Groups multiple transactions for efficiency
- Smart Contract Interactions: Interacts with DeFi protocols like Uniswap, Aave, Sushiswap, PancakeSwap, and Balancer
- API Integration: Connects to various APIs for blockchain and market data
- Configurable Parameters: Allows adjustment of parameters, strategies, and risk levels
- Detailed Logging: Provides logs of activities, transactions, and strategies
- Customizable: Supports multiple wallets, tokens, and trading pairs
/0xBuilder/
├── abi/
│ ├── uniswap_abi.json
│ ├── erc20_abi.json
│ └── aave_pool_abi.json
├── contracts/
│ ├── SimpleFlashloan.sol
│ └── IERC20.sol
├── linear_regression/
│ ├── training_data.csv
│ └── price_model.joblib
├── python/
│ ├── safety_net.py
│ ├── strategy_net.py
│ ├── mempool_monitor.py
│ ├── market_monitor.py
│ ├── main.py
│ ├── transaction_core.py
│ ├── main_core.py
│ ├── nonce_core.py
│ ├── api_config.py
│ ├── configuration.py
| ├── abi_registry.py
│ ├── 0xBuilder.log
| ├── __init__.py
│ └── pyutils/
│ ├── strategyexecutionerror.py
│ ├── strategyconfiguration.py
│ └── colorformatter.py
├── utils/
│ ├── token_addresses.json
│ ├── erc20_signatures.json
│ └── token_symbols.json
├── .env
└── requirements.txt
- abi/: Contains JSON files for various smart contract ABIs.
- contracts/: Includes Solidity smart contracts.
- linear_regression/: Contains data and models for regression analysis.
- python/: Contains Python scripts forming the core functionality.
- utils/: Stores utility JSON files for token data.
- Logs/: Maintains log files for tracking activities.
- requirements.txt: Lists Python dependencies.
Ensure the following before running 0xBuilder:
- Operating System:
- Linux (Ubuntu 20.04+ recommended)
- Windows 10/11
- macOS 12+
- Network:
- Internet: Minimum 50Mbps (100Mbps recommended)
- Hardware:
- CPU: 4+ cores, 3.0GHz+ (Intel i7/Ryzen 7 or better recommended)
- RAM: Minimum 16GB (32GB recommended)
- Storage: Minimum 1.3TB NVMe SSD (2TB recommended)
- Execution Client: execution client compatible with Ethereum, see Ethereum Node Setup
- Development Tools:
- web3.py
- Python packages from
requirements.txt
- Git: Latest stable version
- Docker: Optional for containerization
- Build Tools: make, gcc, platform-specific compilers
Choose and set up an execution client compatible with Ethereum:
Client | Language | OS Support | Networks | Sync Methods |
---|---|---|---|---|
Geth | Go | Linux, Windows, macOS | Mainnet, Sepolia, Holesky | Snap, Full |
Nethermind | C#/.NET | Linux, Windows, macOS | Mainnet, Sepolia, Holesky | Snap, Fast, Full |
Besu | Java | Linux, Windows, macOS | Mainnet, Sepolia, Holesky | Snap, Fast, Full |
Erigon | Go | Linux, Windows, macOS | Mainnet, Sepolia, Holesky | Full |
Reth | Rust | Linux, Windows, macOS | Mainnet, Sepolia, Holesky | Full |
EthereumJS | TypeScript | Linux, Windows, macOS | Sepolia, Holesky | Full |
-
Installation: Follow the official Geth installation guide.
-
Launch Node:
./geth --mainnet --syncmode snap --http --http.api eth,net,admin,web3,txpool --ws --ws.api eth,net,admin,web3,txpool --maxpeers 100 --cache 16000 --ipcpath ~/0xBuilder/geth.ipc --allow-insecure-unlock --http.corsdomain "*"
- Monitor Sync:
# Connect to node
geth attach ipc:/path/to/geth.ipc
# Check sync status
> eth.syncing
- Installation: Follow the official Prysm installation guide.
curl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh --output prysm.sh
chmod +x prysm.sh
- Launch Node:
./prysm.sh beacon-chain --accept-terms-of-use --execution-endpoint ~/0xBuilder/geth.ipc --mainnet --checkpoint-sync-url https://beaconstate.info --genesis-beacon-api-url https://beaconstate.info
Install either:
git clone https://github.com/John0n1/0xBuilder.git
cd 0xBuilder
Using a virtual environment manages dependencies:
For Linux/MacOS:
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
- Create a
.env
file:
# Linux/MacOS
cp .env.example .env
# Windows
copy .env.example .env
-
Configure variables:
- Add API keys
- Set node endpoints
- Configure wallet details
-
Validate configuration:
ls -la .env
chmod 600 .env
Example .env
:
# API Configuration
ETHERSCAN_API_KEY=your_etherscan_api_key
INFURA_PROJECT_ID=your_infura_project_id
COINGECKO_API_KEY=your_coingecko_api_key
COINMARKETCAP_API_KEY=your_coinmarketcap_api_key
CRYPTOCOMPARE_API_KEY=your_cryptocompare_api_key
# Ethereum Node Configuration
HTTP_ENDPOINT=http://127.0.0.1:8545
WS_ENDPOINT=wss://127.0.0.1:8546
IPC_ENDPOINT=/path/to/geth.ipc
# Wallet Configuration
PRIVATE_KEY=your_private_key
WALLET_ADDRESS=0xYourWalletAddress
# Token Configuration
TOKEN_ADDRESSES=utils/token_addresses.json
TOKEN_SYMBOLS=utils/token_symbols.json
# DEX Router Configurations
UNISWAP_ADDRESS=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
SUSHISWAP_ADDRESS=0xd9e1cE17F2641f24aE83637ab66a2cca9C378B9F
# ABI Paths
UNISWAP_ABI=abi/uniswap_abi.json
SUSHISWAP_ABI=abi/sushiswap_abi.json
ERC20_ABI=abi/erc20_abi.json
# Flashloan Configuration
AAVE_ADDRESS=0xYourFlashloanContractAddress
AAVE_POOL_ADDRESS=0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
Ensure JSON files in utils
are properly formatted:
File | Description | Format |
---|---|---|
token_addresses.json |
Monitored token contracts | {"symbol": "address"} |
token_symbols.json |
Address to symbol mapping | {"address": "symbol"} |
erc20_signatures.json |
ERC20 function signatures | {"name": "signature"} |
Deploy a flashloan contract compatible with Aave V3.
- Launch Remix IDE
- Create
SimpleFlashloan.sol
- Implement flashloan logic per Aave's specifications
- Compile with Solidity v0.8.19+
- Deploy via MetaMask
- Update
.env
with contract address
-
Example Flashloan Contract AAVE V3:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "https://github.com/aave/aave-v3-core/blob/master/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol"; import "https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPoolAddressesProvider.sol"; import "https://github.com/aave/aave-v3-core/blob/master/contracts/dependencies/openzeppelin/contracts/IERC20.sol"; contract SimpleFlashLoan is FlashLoanSimpleReceiverBase { address payable public owner; event FlashLoanRequested(address token, uint256 amount); event FlashLoanExecuted(address token, uint256 amount, uint256 premium, bool success); constructor(address _addressProvider) FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider)) { owner = payable(msg.sender); } modifier onlyOwner() { require(msg.sender == owner, "Not contract owner"); _; } function fn_RequestFlashLoan(address _token, uint256 _amount) public onlyOwner { emit FlashLoanRequested(_token, _amount); POOL.flashLoanSimple(address(this), _token, _amount, "", 0); } function executeOperation( address asset, uint256 amount, uint256 premium, address initiator, bytes calldata params ) external override returns (bool) { require(IERC20(asset).approve(address(POOL), amount + premium), "Approval failed"); emit FlashLoanExecuted(asset, amount, premium, true); return true; } function withdrawToken(address _tokenAddress) public onlyOwner { IERC20 token = IERC20(_tokenAddress); uint256 balance = token.balanceOf(address(this)); require(balance > 0, "No tokens to withdraw"); token.transfer(owner, balance); } function withdrawETH() public onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "No ETH to withdraw"); owner.transfer(balance); } receive() external payable {} }
-
Update Configuration:
AAVE_ADDRESS=0xYourDeployedContract
Register and obtain API keys from:
- Infura
- Etherscan
- CoinGecko
- CoinMarketCap
- CryptoCompare
- Binance (optional)
Store all API keys securely.
- Synchronized Ethereum node
- Active beacon node
- Configured environment variables
- Valid API keys
- Deployed flashloan contract
- Wallet with with balance sufficient for gas fees
-
Activate environment:
source venv/bin/activate
-
Start bot:
python python/main.py
- Check
python/0xBuilder.log
for logs - Monitor console for real-time status
- Use
Ctrl+C
to shutdown gracefully
- Keep node fully synced
- Monitor API rate limits
- Maintain sufficient ETH balance
- Regularly check logs
- Update dependencies as needed
0xBuilder implements several trading strategies to capitalize on Ethereum network opportunities:
- Front-Running: Executes transactions ahead of profitable ones.
- Back-Running: Executes transactions immediately after profitable ones.
- Sandwich Attacks: Combines front- and back-running around target transactions.
- Flashloan Arbitrage: Uses flashloans for arbitrage without initial capital.
- Nonce Management: Ensures proper transaction ordering.
- Dynamic Gas Optimization: Adjusts gas prices based on network conditions.
- Real-time Market Analysis: Identifies profitable opportunities.
- Safety Protocols: Validates transactions and assesses risks.
- Transaction Bundling: Groups multiple transactions per block.
Logs are maintained in python/0xBuilder.log
, including:
- Transaction detections
- Strategy executions
- Errors and exceptions
- Transaction results
Configure logging in python/main_core.py
via setup_logging()
.
Issue | Solution |
---|---|
Node Connection Failures | Verify node status and endpoints |
API Rate Limit Exceeded | Implement throttling or upgrade API tier |
Insufficient Gas Balance | Ensure adequate ETH for fees |
Nonce Synchronization | Reset nonce manager or synchronize manually |
Node Sync Status | Ensure full node synchronization |
- Enable verbose logging
- Keep dependencies updated
- Verify contract deployment on explorers
- Test on testnets before mainnet
Review CONTRIBUTING.md for guidelines. Contributions are most welcome! ❤️❤️
- Fork the repository
- Create a feature branch
- Follow PEP 8
- Include unit tests
- Submit a pull request
Licensed under the MIT License. See LICENSE file for details.
IMPORTANT: Me the author, and the project contributors, are not responsible for any financial losses or damages incurred by using 0xBuilder. Use at your own risk. Not in any instance should any contributor, author, or the project be held liable for any financial losses or damages. Use 0xBuilder at your own risk and discretion.
- Strategies may be aggressive or unethical
- Cryptocurrency trading carries financial risks
- Smart contracts may have vulnerabilities
Thanks to the following projects creating the foundation of many projects including this one: