How to install a Hyperledger Fabric network in localhost

Iván Alberquilla
4 min readJan 7, 2020

--

Introduction

This is the first of a series of posts about Hyperledger Fabric, in which we will see how this blockchain network works, since its installation until the creation of chaincodes and the creation of a rest api to interact with the network.

Dependencies installation

This manual is created using a Ubuntu 18.04 local machine.

First of all we should install go, the language in which hyperledger is written and establish its instalation path to be accesible. To do this, we first install with:

sudo apt-get install golang-go

And for include it in the path, let’s do:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

The chaincodes, which are the hyperledger smart contracts, could be written in go, nodejs Python or Java, so we will install the dependencies. In this series of post, we will use nodejs to create the chaincodes and use the sdk. To install this dependencies:

sudo apt-get install curl
curl -sL
https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install python

Hyperledger fabric is based on docker containers, so we should install docker. First we need to install the GPG repository key to our local repository:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

Then we need to update the package repository with the just installed dependencies

sudo apt-get update

After updating them, we check if the package selected is the one that is going to be installed:

apt-cache policy docker-ce

The output should be something like this, where we can see than the selected resource is poiting to ubuntu version:

With these checks, let’s install now docker:

sudo apt-get install -y docker-ce
sudo apt-get install docker-compose
sudo apt-get upgrade

In order to verify that docker is up and running we can do:

sudo systemctl status docker

this should return something like this:

After all we will download the docker images of hyperledger fabric by executing the next command. The -s signal specify the fabric version. If this option is not shown the latest version should be downloaded.

sudo curl -sSL https://goo.gl/6wtTN5 | sudo bash -s 1.4.3

In order to verify that everything has been installed correctly, fabric brings by default a test network, which we can start. We could navigate within the downloaded files to the route where the default network is located and generate

cd fabric-samples/first-network
./byfn.sh generate

Starting the network

We can start the network, executing the command

./byfn.sh up

We will be asked for confirmation to start the network, we have to confirm to start with the default configuration

Once confirmed, we will see that it begins to create the docker containers and start them

After starting them, it joins the peers with the channel created and installs the chaincodes by default, all this steps will be shown in future posts.

Once everything is started correctly it shows us the following message

If we want to verify which containers have started we can see it by executing the command

docker ps

we will see that it shows us the containers of the peers that have been created in the network

If we want to shut down the network, we can use

./byfn.sh down

the running containers will be stopped

If we see again which containers are now running, with docker ps, we will see that none exists.

Following these steps we finally have installed our local fabric network and verified that it works. In the next posts we will go deeper into this test network, identifying the components and modifying them to suit on our case of use.

--

--

Iván Alberquilla

After 9 years developing banking technology, bumping into blockchain was not a coincidence. linkedin.com/in/ialberquilla twitter.com/ialberquilla