Let’s get a blockchain

  • April 23rd, 2024
  • Test&train
  • 0 Comments
  • Robert Pardela

Ta strona dostępna jest w języku polskim

You will ask why bother with installing your blockchain if ready-made solutions are available with a single click on popular cloud platforms?

Personally, I think it’s worth learning how blockchain works from scratch before using ready-to-go solutions. Then we can use the ready-made solutions in a conscious manner.

I will show you the blockchain installation process using the example of Ethereum platform. This installation will be used in subsequent entries, for example, for the creation of a smart contract.

To make it harder I will show you how to install Ethereum from Go sources, and for the less inquisitive I will present the installation from binary versions.

Installation on Mac OS is trivially simple, on Windows I did not install, and in this post we will do it on Linux.

The installation will take place on a virtual machine built with minimal ISO Centos7 image.

Do not install on root user, if any step of the installation will require higher permissions then we will handle it with sudo.

 

Installation of ethereum in GO (geth) version with building geth from sources.

  • Check out the version of the GO package at https://golang.org/dl/

  • on the centos, go to catalogue /tmp:

    cd /tmp

  • download the latest version (in my case 1.11.5) of the GO package:

    curl -LO https://storage.googleapis.com/golang/go1.11.5.linux-amd64.tar.gz

  • extract the package to the directory on the centos /usr/local :

    sudo tar -C /usr/local/ -xvf ./go1.11.5.linux-amd64.tar.gz

  • export the GOROOT variable:

    export GOROOT=/usr/local/go

  • add the GOROOT variable to the PATH path:

    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

  • create a go.sh file:

    “ sudo touch ” etc/profile.“ ” go.sh

  • edit the /etc/profile.d/go.sh file

  • type in to him:

    export GOPATH=/usr/local/go

    export GOROOT=/usr/local/go

    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

  • Install the guitar:

    sudo yum install git

  • on the centos go to the opto directory:

    cd opt

  • Copy to the /opt directory of the geth repository: 

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

  • go to the directory /opt/go-ethereum:

    cd go-ethereum go-ethereum

  • build a geth:

    make geth

If you experience any errors in the above step, install the development tools and repeat building geth:

sudo yum install gcc gcc-c-c+++

If everything went well, it’s in the catalog: /opt go-ethereum build/bin you have a binary file geth. This is what the node software is all about.

 

Now it’s time to show a simpler and faster installation procedure.

 

Installation of ethereum in GO (geth) version with download of binary.

  • on the centos, go to catalogue /tmp:

    cd /tmp

  • download the latest version (in this case 1.8.23) of the geth package:

    curl -LO https://gethstore.blob.core.windows.net/builds/geth-linux-amd64–1.8.23-c9427004.tar.gz

  • extract the package to the /opt/go-ethereum/build/bin directory:

    sudo tar -C /usr/local/ -xvf ./geth-linux-amd64–1.8.23-c9427004.tar.gz

I chose the same catologue as in step 1A, because the rest will be common for both versions of the installation.

You can also download a set of the latest Ethereum tools:

curl -LO https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64–1.8.23-c9427004.tar.gz

Behind geth you will find other tools that I will discuss in the following entries, for example swarm distributed filesystem.

We have installed the required software, so now we can go to run our test blockchain.

 

Launching a private test network:

  • on the centos in your user’s home directory, create an ethnode directory:

    cd home/yourusername

    mkdir eth-node

  • go to the eth-node directory:

    ” Cd eth-node

  • in the eth-node directory, create a localGenesis.json file:

    sudo touch etc-node/localGenesis.json

  • edit the localGenesis.json file

  • enter the following text into it:

    {

    “config”: {

    “chainId”: 1000,

    “HomesteadBlock”: 0,

    “eip155Block”: 0,

    “eip158Block”: 0,

    “ByzantiumBlock”: 0

    },

    “difficulty.” “10”,

    “gasLimit”: “2000000”

    }

The above example file localGenesis.json contains the content of the first initial block in our blockchain. All subsequent nodes will have to have the same initial block otherwise they will not be able to connect to our string. The private blockchain initialization file can contain many other parameters. Below I will describe only some of them:

chainId – that’s the blockchain ID. The identifiers 1 to 61 are reserved for the Ethereum network, e.g. 1 is the main Ethereum network.

difficulty – the level of difficulty in the extraction of units, the higher the value the more energy-intensive the extraction is.

GasLimit – Gas unit limit for each block (for now black magic :))

 

  • initiate the first knot of our blockchain:

    sudo /opt/go-ethereum/build/bin/geth –datadir ./eth-node init ./localGenesis.json

  • activate the local ethereum node:

    sudo /opt/go-ethereum/build/bin/geth –identity “Main” –datadir ./eth-node –networkid 1114 -verbosity 4 –port 30303 -nodiscover console 2>>>./eth.log

If everything went well, you just saw the geth console.

 

Several parameters for calling a node need to be described:

identity – name of the node (optional parameter). Each node should have a different name. This name appears e.g. in the logs. It can be useful for analysing chain problems.

datadir – directory of our node. It was created when the node was initialized.

networkid – the identifier of our network of nodes. Subsequent nodes will connect to this node if they have the same network.

verbosity – event logging level (the higher the higher the number of log entries)

port – port – port after which we will connect to this node

nodiscover – other nodes will not be able to find this node automatically. This is a protection if we do not want someone unwanted to connect to our node from the outside.

 

Check private blockchain

Commands executed in the geth console.

Opening a new account at ethereum:

  • Create a new account at geth console:

    personal.newAccount(“type in and remember your password here”)

    • you’ll see the address of the new account. Please write them together with the above password

Set the default account:

  • Check the available accounts:

    ” Eth.coinbase

    • if the address is the same as in the previous step then do nothing
    • if the address is different then check which account is yours:

      eth.accounts, you get something like [“0x2b1b054979ba9aff03b02a1c8a1d1d1d6122f17da6”, “0x5b8e0cbc7ae34d214884349460e557945546cee8”, “0xd6271f8c29d5d563b4a7efe9fa56f2f395caabae”]

      • counting from zero, set your account as the correct one, e.g:

        Mineral.setEtherbase(eth.accounts[2])

Starting the mines:

  • Check your current account balance:

    eth.getBalance(eth.coinbase)

    • the first time should be 0
  • start digging:

    miner.start()

    • the log should show the status of processed blocks
  • After some time (~30 seconds) check your account balance again:

    eth.getBalance(eth.coinbase)

    • now the value should be > 0
  • stop digging:

    miner.stop()

 

Summary

Congratulations on just installing, configuring and running the first private blockchain node. You even dug yourself some crypto-currency.) The bad news is that this is a currency only available in your local blockchain.

Now I encourage you to experiment with blockchain initialization parameters and call parameters.

In the next entries we will install another node and create a small blockchain network.

Normally, if you have any questions I encourage you to contact me.

 

 

Robert Pardela

Leave a Comment

Your email address will not be published.

18 − 18 =