Mining on Linux

script was made for Docker but can be used for Geth *USE sudo everytime you call docker command*


Ensure TCP Port 30303 is open

Ensure Docker is installed and started, then pull the ethereum image

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli docker-compose-plugin
sudo groupadd docker sudo usermod -aG docker $USER
####### CHAIN_NAME="berylbit" CHAIN_ID="9012" NETWORK_ID="9012" WORKING_DIR=$HOME'/.'$CHAIN_NAME'-docker' CONTAINER_NAME_PREFIX="$CHAIN_NAME-node" BOOTNODE_URL="enode://6c2cc2b8184b5fd75e7ae6c00ae5bfc64e505089ad8fb018306845f5a4d94bd89[email protected]" NODE_ROLE="miner" CONTAINER_IMAGE="berylbit/go-ethereum:0.0.4" WALLET_PASSWORD="anbisnagjaikdf" ## please change this value. OK sir. (don't copy this password)

Iniialize the blockchain

mkdir -p $WORKING_DIR/$NODE_ROLE cat << EOF > $WORKING_DIR/$NODE_ROLE/genesis.json { "config": { "chainId": $CHAIN_ID, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "istanbulBlock": 0, "berlinBlock": 0, "londonBlock": 0 }, "alloc": { "0x768A5e67b3E8cf3c5562dd221b12B62438F43184": { "balance": "300000000000000000000000000" } }, "coinbase": "0x0000000000000000000000000000000000000000", "difficulty": "0x20000", "extraData": "", "gasLimit": "0x2fefd8", "nonce": "0x0000000000000042", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x00" } EOF
docker run -v $WORKING_DIR/$NODE_ROLE:/root --rm -i --platform linux/amd64 $CONTAINER_IMAGE init /root/genesis.json
MINING_WALLET_ADDRESS=$(echo "$WALLET_PASSWORD $WALLET_PASSWORD" | docker run -v $WORKING_DIR/$NODE_ROLE:/root --rm -i --platform linux/amd64 $CONTAINER_IMAGE account new | sed -n 's/Public address of the key: //p' )
docker kill $CONTAINER_NAME_PREFIX-$NODE_ROLE docker rm $CONTAINER_NAME_PREFIX-$NODE_ROLE docker run -d --name $CONTAINER_NAME_PREFIX-$NODE_ROLE -v $WORKING_DIR/$NODE_ROLE:/root --platform linux/amd64 -p 30303:30303 -p 30303:30303/udp $CONTAINER_IMAGE --port=30303 --mine --miner.threads=1 --miner.etherbase $MINING_WALLET_ADDRESS --networkid=$NETWORK_ID --bootnodes=$BOOTNODE_URL
PEERS=$(docker run -v $WORKING_DIR/$NODE_ROLE:/root --rm -i --platform linux/amd64 $CONTAINER_IMAGE attach --exec "admin.peers" | tr -d '"')
echo $PEERS