Ethereum Private Network Construction

I wrote this document for sharing my experience for constructing the private ethereum blockchain. 


https://www.virtualbox.org/wiki/Downloads


https://ubuntu.com/download/desktop

I deployed "Ubuntu 20.04.3 LTS"


$ sudo apt install git

$ mkdir ethereum

$git clone https://github.com/ethereum/go-ethereum.git 

$cd go-ethereum

$sudo apt-get install -y build-essential golang

$sudo make all

      During above step, there could be error like "hash/maphash": missing dot in first path element". I looked up with the error message and got some solution. 

      I just upgrade the go language version and re-install the build-essential go lang. 

     $ wget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz

     If above command is not working, we could download the file from the website of the go language. 

     $ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xvf go1.1.7.3.linux-amd64.tar.gz

     I added below shell variable update for this installation. However you could add it to .profile of the user home directory. 

     $ export PATH=$PATH:/usr/local/go/bin

     Please check the "go" can be executed in your directory.

     $go version

    Another things I tried is shown as below. 

     $sudo add-apt-repository ppa:longsleep/golang-backports

     $sudo apt update

     $sudo apt install golang-go

     $sudo make all

     It takes more than 30 minutes in my envornment to make all the geth (I don't know why it takes so long, I thought it is caused by the network delay and virtual box)

$cd build/bin 

$geth version

$vim ~/.bash_profile

add below two lines for the geth's executions.

GETH=/home/john/ethereum/go-ethereum

PATH="$PATH:$GETH/build/bin"

$source ~/.bash_profile


$cd ../../../

$mkdir data


$vim data/password

123456789 

$geth --datadir data account new --password data/password

You can find the account information from the keystore directory.

$ls -al data/keystore


{

  "config": {

    "chainId": 10,

    "homesteadBlock": 0,

    "eip150Block": 0,

    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",

    "eip155Block": 0,

    "eip158Block": 0,

    "byzantiumBlock": 0,

    "constantinopleBlock": 0,

    "petersburgBlock": 0,

    "istanbulBlock": 0,

    "ethash": {}

  },

  "nonce": "0x0",

  "timestamp": "0x5e4a53b2",

  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",

  "gasLimit": "0x47b760",

  "difficulty": "0x80000",

  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",

  "coinbase": "0x0000000000000000000000000000000000000000",

  "alloc": {

    "0000000000000000000000000000000000000088": {

      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"

    }

  },

  "number": "0x0",

  "gasUsed": "0x0",

  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"

}

$geth --datadir data init data/genesis.json 


$sudo apt-get install pcscd

$sudo service pcscd start


$ cd ~/ethereum

$ geth --networkid 7402 --nodiscover --datadir data --http.addr 0.0.0.0 --http --http.port 8545 --http.corsdomain "*" --http.api="db,eth,net,web3,personal,web3,miner,admin" --miner.threads 1 console 2>> data/geth.log 

The documents that I referred presented the --rpc flag but currently it is not working and replaced with http. 


> eth.coinbase

> miner.start()

The miner.start may return 'null' however you don't need to worry and please check the mining result using below command.

> eth.blockNumber

will return the number of mined blocks

> web3.eth.mining

will return "true", if the mining is proceeding. 


> eth.sendTransaction({from : eth.coinbase, to : eth.accounts[1], value : web3.toWei(1,'ether')}); 

How ever to make it work, we need to unlock the account using a commands.

> personal.unlockAccount(eth.coinbase,'',0); 

In some enviroment, above command is not working, in that case re-start the geth using below command. 

>exit

$ geth --networkid 7402 --nodiscover --datadir data --http.addr 0.0.0.0 --http --http.port 8545 --http.corsdomain "*" --http.api="db,eth,net,web3,personal,web3,miner,admin" -allow-insecure-unlock --miner.threads 1 console 2>> data/geth.log


$geth attach http://localhost:8545

      If the geth path does not working, execute below command again. 

$source ~/.bash_profile


     > personal.newAccount()

     >miner.setEtherbase(eth.accounts[0])

      >eth.coinbase

      >miner.start()


$ geth --networkid 7402 --nodiscover --datadir data --http.addr 192.168.0.100 --http --http.port 8545 --http.corsdomain "*" --http.api="db,eth,net,web3,personal,web3,miner,admin" -allow-insecure-unlock --miner.threads 1 console 2>> data/geth.log


      create a <geth.sh> file

     geth --networkid 7402 --nodiscover --datadir data --http.addr "0.0.0.0" --http --http.port 8545 --http.corsdomain "*" --http.api="db,eth,net,web3,personal,web3,miner,admin" -allow-insecure-unlock --miner.threads 1 2>> data/geth.log

    

    creat a <geth.service> file 

[Unit]

Description=Ethereum go client

[Service]

Type=simple

ExecStart=/bin/bash geth.sh

[Install]

WantedBy=default.target

    $ systemctl enable geth.service