How to Set Up a BSC Geth Node on Ubuntu - Step-by-Step Guide

08 October 2023
How to Set Up a BSC Geth Node on Ubuntu - Step-by-Step Guide
How to Set Up a BSC Geth Node on Ubuntu - Step-by-Step Guide

Setting up a Binance Smart Chain (BSC) Geth node on Ubuntu is a crucial step for anyone interested in participating in the Binance Smart Chain ecosystem. BSC, as an Ethereum-compatible blockchain, has gained significant popularity, and running a Geth node allows you to interact with and support the network. In this comprehensive guide, we'll walk you through the process of setting up your own BSC Geth node on an Ubuntu server.

 

Step 1: Prerequisites

Before we begin, make sure you have the following prerequisites in place:

  • An Ubuntu server (ideally 18.04 LTS or later) with SSH access.
  • Basic knowledge of the Linux command line.
  • Sufficient disk space and resources for running a Geth node. (>= 2TB eNVM)

Step 2: Update Your System

First, log in to your Ubuntu server and update the system's package list to ensure you have the latest software versions:

sudo apt update && sudo apt upgrade -y

Step 3: Sync From Snapshot (Recommended)

  1. Download the pre-build binaries from the release page or follow the instructions below
    # 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

    # MacOS
    wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_mac |cut -d\" -f4)
    mv geth_mac geth
    chmod -v u+x geth
  1. Download the config files
    Download genesis.json and config.toml by:
    wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\" -f4)
    unzip mainnet.zip
  1. Download snapshot

Download latest chaindata snapshot from here. Follow the guide to structure your files.

NOTE

Your --datadir flag should point to the folder where the extracted snapshot data is. In our case, we created a new folder named node, and we moved the extracted snapshot data to this folder.

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

4. Go to the folder where you stored node data, and run nohup script to run the node in background

 

nohup ./geth --config ./config.toml --datadir ./node --cache 8000 --http --http.api eth,net,web3,txpool --http.corsdomain '*' -ws --ws.port 3334 --ws.api eth,net,web3,txpool --ws.origins '*' --rpc.allow-unprotected-txs --txlookuplimit 0 --tries-verify-mode none --nodiscover > geth.log 2>&1 &

5. Last Step, attach the console 

geth attach ./node/geth.ipc
Consider that if you close/interupt attach or step 4, the sync will not start

To check if node is syncing, in your geth console (step 5) you can run eth.blockNumber or eth.syncing 

if response is boolean then Sync is not in progress.