> For the complete documentation index, see [llms.txt](https://berylbit-labs.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://berylbit-labs.gitbook.io/product-docs/product-guides-1/node-and-mining-setup/mining-on-linux.md).

# Mining on Linux

## Pre-requisites

{% hint style="info" %}
Pre-Requisites :&#x20;

Ensure TCP Port 30303 is Open

`Sudo ufw enable`

`sudo ufw allow from any to any port 30303 proto tcp`

`sudo ufw allow from any to any port 30303 proto udp`
{% endhint %}

```
sudo apt-get update
```

```
sudo apt-get install -y
ca-certificates
curl
gnupg
lsb-release
```

```
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
```

```
echo
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
$(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 containerd.io docker-compose-plugin
```

```
sudo groupadd docker 
```

```
sudo usermod -aG docker $USER
```

Variable Declaration :

```
CHAIN_NAME="berylbit" 
CHAIN_ID="9012" 
NETWORK_ID="9012" 
WORKING_DIR=$HOME'/.'$CHAIN_NAME'-docker' 
CONTAINER_NAME_PREFIX="$CHAIN_NAME-node" 
BOOTNODE_URL="enode://6c2cc2b8184b5fd75e7ae6c00ae5bfc64e505089ad8fb018306845f5a4d94bd896a38c065f5ae480e456ff8fea4e4429c1f05640539c98ab6de8439a293370c0@45.63.108.190:30303" 
NODE_ROLE="miner" 
CONTAINER_IMAGE="berylbit/go-ethereum:0.0.4" 
WALLET_PASSWORD="xxxxxxxxxxx"
```

Please alter this value of "xxxxxxxxxxx"

## Initialize the blockchain

Create new folder as working directory

```
mkdir -p $WORKING_DIR/$NODE_ROLE
```

Create new genesis.json file

```
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
```

Create new mining wallet

```
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'
)
```

Display the value of $MINING\_WALLET\_ADDRESS in Linux terminal

```
echo $MINING_WALLET_ADDRESS
```

```
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
```

```
PEERS=$(docker run \
  -v $WORKING_DIR/$NODE_ROLE:/root \
  --rm \
  -i \
  --platform linux/amd64 \
  $CONTAINER_IMAGE attach \
  --exec "eth.sync" | tr -d '"')
```

Check Mining Wallet Balance

```
PEERS=$(docker run \
  -v $WORKING_DIR/$NODE_ROLE:/root \
  --rm \
  -i \
  --platform linux/amd64 \
  $CONTAINER_IMAGE attach \
  --exec "eth.getBalance('xxxxxxxxxxxxxxxxxxxxxxxx')"
```

please replace xxxxxxxxxxxxxxxx string with your mining wallet.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://berylbit-labs.gitbook.io/product-docs/product-guides-1/node-and-mining-setup/mining-on-linux.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
