This guide shows how to quickly start mining with reth-bsc using automatic key generation.
Just set one environment variable and start mining:
export BSC_MINING_ENABLED=true
cargo run -- --chain bsc --datadir ./test-datadirThat's it! The system will:
- ✅ Automatically generate a validator private key
- ✅ Derive the validator address from the key
- ✅ Start mining with proper Parlia consensus
- ✅ Display your keys in the logs (save them!)
When you start mining, you'll see logs like this:
WARN Mining enabled but no keys provided - generating development keys
WARN 🔑 AUTO-GENERATED validator keys for development:
WARN 📍 Validator Address: 0x1234567890abcdef1234567890abcdef12345678
WARN 🔐 Private Key: 0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef (KEEP SECURE!)
WARN ⚠️ These are DEVELOPMENT keys - do not use in production!
INFO Starting BSC mining service for validator: 0x1234567890abcdef1234567890abcdef12345678
💾 SAVE THESE KEYS! You'll need them to continue mining with the same identity.
# Enable/disable mining
export BSC_MINING_ENABLED=true
# Use your own keys (optional)
export BSC_PRIVATE_KEY=0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
# Mining parameters (optional)
export BSC_GAS_LIMIT=30000000
export BSC_MINING_INTERVAL_MS=500If you have existing validator keys:
export BSC_MINING_ENABLED=true
export BSC_PRIVATE_KEY=0xYOUR_PRIVATE_KEY
cargo runBSC_MINING_ENABLED=true cargo run -- --chain bsc --datadir ./datadirDevelopment (Current Setup):
- ✅ Auto-generates keys for easy testing
- ✅ Keys displayed in logs for convenience
⚠️ Not secure for real BSC network
Production Setup:
- 🔒 Store keys in hardware security modules (HSM)
- 🔒 Never log private keys
- 🔒 Use environment variables or secure vaults
# Generate secure private key
openssl rand -hex 32
# Or use existing BSC validator keys
# Make sure your validator is registered on the BSC networkMonitor your mining activity:
# Watch for mining logs
tail -f logs/reth.log | grep -i mining
# Key log messages:
# - "Starting BSC mining service"
# - "Mining new block on top of block"
# - "Successfully mined block"BSC_MINING_ENABLED=true cargo runBSC_MINING_ENABLED=true \
BSC_PRIVATE_KEY=0xabc... \
cargo runConfig files are not supported. Use env vars or CLI.
INFO Mining is disabled in configuration
Solution: Set BSC_MINING_ENABLED=true
ERROR Failed to create mining service: No signing key configured
Solution: Check that BSC_MINING_ENABLED=true and restart
WARN Failed to open database for mining: ..., mining disabled
Solution: Make sure the --datadir path exists and is writable
DEBUG Mining attempt failed: Not authorized validator: 0x...
Solution: Your validator isn't in the current validator set. This is normal for development - you're testing the mining logic even if blocks won't be accepted by the real network.
- Test Basic Mining: Start with auto-generated keys
- Save Your Keys: Copy the generated keys for reuse
- Monitor Logs: Watch for successful block creation
- Customize Config: Set gas limits, intervals, etc.
- Production Setup: Implement proper key management
BSC_MINING_ENABLED=true BSC_GAS_LIMIT=25000000 cargo runBSC_MINING_ENABLED=true BSC_MINING_INTERVAL_MS=200 cargo runuse reth_bsc::node::mining_config::MiningConfig;
// Quick development setup
let config = MiningConfig::development();
// Or from environment
let config = MiningConfig::from_env();- Auto-generated keys are for DEVELOPMENT only
- Save the generated keys if you want to reuse the same validator identity
- Mining will work but blocks may not be accepted without proper validator registration
- This is perfect for testing mining logic and development
Start mining now with just one command:
BSC_MINING_ENABLED=true cargo run -- --chain bsc --datadir ./test-mining