Run a local test network for Hyperledger Fabric v2.x on Ubuntu 20.04 (Updated on 2021–05–04)

Akarsh Agarwal
3 min readMar 20, 2019

--

This entire tutorial is the second part of the installation of Hyperledger Fabric v2.x. In the previous article, we installed all the dependencies required to make the Fabric environment run. In this part of the tutorial, we aim to launch our example network, execute some transactions, and query the Blockchain network to retrieve the values.

So, at first, Hyperledger Fabric Project’s “fabric-samples” repo provides many detailed examples and documentation. The one we’ll be using is the “asset-transfer-basic” code example.

To get started, we first need to clone the fabric-samples repo on your machine. So, go ahead and fire the command below:

git clone https://github.com/hyperledger/fabric-samples.git

After cloning the project to a safe location, migrate to the branch master by using the command:

git checkout master

And make sure the directory structure is similar to the one described below:

<work directory>/src/github.com/hyperledger/fabric-samples

Please refer to the below image for further explanation:

I already have the project cloned. But, in the end, you should have the fabric-samples repo in your current directory. We need some functions to be build to ensure our smooth journey towards the execution environment. So, we need to build functions, like:

configtxgen
cryptogen

This list is not exhaustive, but these are the most important ones. “configtxgen” takes in configtx.yaml file and builds your genesis block for the channel, which contains metadata associated with the channel, which is broadcast to the Orderer. So, this is like Block 0 of the network, which is needed to ensure that our chaincode is deployed on top of it. The cryptogen is used to generate the certificates according to the organizational structure of the organizations participating in the blockchain.

To enable the building of the tools, we need to set the GOPATH variable in the ~/.bashrc or ~/.bash_profile file of the user logged into. This is to enable fabric-samples to locate the source code. For that, we add the following line to the ~/.bashrc or ~/.bash_profile file:

export GOPATH=/home/ubuntu

GOPATH will always be your work directory. So, if you have a different working directory, then please state that as your GOPATH. Now, we are ready to download the binaries required for the Hyperledger Fabric examples to run. To download all the binaries, the “fabric-samples” repo and docker images, we use the script provided by the Hyperledger Team:

curl -sSL https://bit.ly/2ysbOFE | bash -s

So, if all goes well, we will have the following output:

You can find that the fabric-samples repo was clone to the current directory. However, there’s a new directory bin present in it. The bin contains all the binaries required to run our test-network application.

So, let’s run the final command and see if the network comes up.

cd fabric-samples/test-network
./network.sh down
./network.sh up

If all goes well, the demo-network should be up and running. If you check the status of the running docker containers using the command,

docker ps

You should get the following responses:

Well, VOILA! You have your first network running. It was fairly simple. We just ran some commands to start the network. Next part of the tutorials will build upon this to deploy a sample app on this network.

Stay Tuned…

--

--

Akarsh Agarwal
Akarsh Agarwal

Written by Akarsh Agarwal

All about Distributed Systems and Stakeholder Management. #golang #distributedsystems #management

No responses yet