Skip to content

Instantly share code, notes, and snippets.

@RajeshRk18
Created April 26, 2024 13:34
Show Gist options
  • Save RajeshRk18/221fd21a87d0b2141d4663ff05f13f87 to your computer and use it in GitHub Desktop.
Save RajeshRk18/221fd21a87d0b2141d4663ff05f13f87 to your computer and use it in GitHub Desktop.

Step1: Download prebuilt binaries

# Linux
wget   $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_linux |cut -d\" -f4)
mv geth_linux geth
chmod -v u+x geth

Step2: Download config files (for mainnet)

# mainnet
wget   $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\" -f4)
unzip mainnet.zip

Step3: Download the snapshot

wget -O geth.tar.lz4 https://snapshots.48.club/geth.full.37756285.tar.zst
tar -I lz4 -xvf geth.tar.lz4

Step4: Move the extracted snapshot to Node folder

mv server/data-seed/geth/chaindata node/geth/chaindata
mv server/data-seed/geth/chaindata node/geth/triecache

Step5: Sync from genesis

./geth --datadir ./node init ./genesis.json

Note: This assumes geth is in current directory

Step6: Modify genesis.json and config.toml to change the chain id

  • Create a file named modify_chainid.sh and paste the below script
#!/bin/bash

if ! command -v jq &> /dev/null; then
    echo "Error: jq is not installed. For Debian based systems, run sudo apt-get install jq"
    exit 1
fi

if [ ! -f genesis.json ]; then
    echo "Error: genesis.json not found in the current directory."
    exit 1
fi

read -p "Enter the new chain ID: " new_chain_id

jq --arg new_chain_id "$new_chain_id" '.config.chainId = $new_chain_id' genesis.json > tmp.json && mv tmp.json genesis.json

if [ ! -f config.toml ]; then
    echo "Error: config.toml not found in the current directory."
    exit 1
fi

sed -i "s/NetworkId = .*/NetworkId = $new_chain_id/" config.toml

echo "Chain ID modified successfully."
  • This script assumes that genesis.json and config.toml are in the directory where you unzipped mainnet.zip.

  • Run the below command and enter chain id.

chmod +x modify_chainid.sh
./modify_chainid.sh

Step7: Run the own private node

Run the below command with the chainID as in config.toml.

## start a full node
./geth --config ./config.toml --datadir ./node  --cache 8000 --networkid=<CHAIN_ID> --rpc.allow-unprotected-txs --history.transactions 0 --syncmode=full --db.engine=pebble
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment