Getting started with Hyperledger Fabric

Gaurang Torvekar
Oct 30, 2016 · 4 min read

This Getting started guide is geared towards Ubuntu users. Other Mac or Linux users can follow this guide with little tweaks to the commands as per their native OS.

I felt a need to write this ‘Getting Started’ guide because, although Hyperledger Fabric has a lot of great documentation, newcomers can get a bogged down due to the sheer number of options in there. Also, I have personally found it easier to get started with the Docker images provided by Yeasy instead of going for a Vagrant setup. Apart from this, I also had to do some trial and error to understand the commands since some of them might not work exactly as intended out of the box (I have mentioned those as suggested changes below). Hence you can consider this as a pragmatic guide to getting started with Hyperledger Fabric.

Before you get started with setting up the blockchain service, you need to install some essential components

  1. You can start by updating and upgrading the package manager
sudo apt-get updatesudo apt-get upgrade

2. Install Docker

You can go directly to Docker’s website at this link —

If you are not familiar with Docker, you can look at the docs here —

Now, you need to install docker-compose. Please note that on Ubuntu, most probably you will get the ‘permission denied’ error if you are not the superuser. Hence, while installing through curl, you need to be a root user.

This is the link —

3. Pull the Yeasy Hyperledger images from docker

Now, it is time to actually pull the images from Docker’s repo. Yeasy has provided really awesome images on Docker for Hyperledger. Using these images you get all the Hyperledger installations out of the box, and you can start using Hyperledger and coding on it quite easily.

This is the link —

This might take some time depending on your internet connection.

Once you have downloaded the images, you are ready to run the Hyperledger blockchain!

4.1 Start the blockchain nodes — NOOPS

Now that you have the yeasy images, it’s relatively simple to start the nodes. Again, you have two options here — you can either run a single node for testing your code without validation. This is called NOOPS in the case of Hyperledger.

NOOPS means no validation. It executes transactions as they arrive.

To run the NOOPS consensus, from the Yeasy image documentation, you can follow the commands under ‘Noops consensus’.

4.2 Start the blockchain nodes — PBFT

The other option for running the blockchain nodes is with the validating mechanism, which currently uses PBFT for consensus.

To do this, you’ll have to run at least 4 nodes at the same time. Again, you can follow the portion — ‘PBFT consensus’ from the Yeasy image documentation.

It first clones a docker-compose file, which has the configuration to run the nodes connected with each other, and then you use docker-compose to run all these 4 nodes at the same time.

There are a few small changes to the commands in this documentation

Change 1 —

Instead of

cd docker-compose-files/hyperledger

you need to do

cd docker-compose-files/hyperledger/pbft

The files seems to have been moved into a sub directory here.

Change 2 —

You need to add ‘sudo’ to all the docker commands

Change 3 —

Instead of

docker exec -it vp0 bash


sudo docker exec -it pbft_vp0_1 bash

The containers that are initialized no longer have the name vp0

5. Start with the ‘chaincode’

Now there are two ways of deploying the chaincode — one through the Command Line, and other through the Node SDK.

In Hyperledger Fabric implementation, a ‘chaincode’ is the actual Smart Contract on the blockchain.

To run through the command line, and get a feel of the chain code, you can start using it directly from the containers you just started

Enter one of the containers by using this command

sudo docker exec -it pbft_vp0_1 bash

First, deploy the chaincode —

peer chaincode deploy -n mycc -p -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'

Then, invoke the chaincode

peer chaincode invoke -n mycc -c '{"Function": "invoke", "Args": ["a", "b", "10"]}'

Then you can query the chaincode

peer chaincode query -n mycc -c '{"Function": "query", "Args": ["a"]}'

6. Try running a sample node app

Now you need to install all the node packages

cd /opt/gopath/src/ all

Go to a /tmp directory, pull the Node.js app file from the github repo and install HFC locally in that directory. Then you can run the node app!

cd /tmpcurl -o app.js install /opt/gopath/src/ CORE_PEER_ADDRESS= MEMBERSRVC_ADDRESS= DEPLOY_MODE=dev node app

If you followed this guide correctly, you would have run a chaincode example and also run a Nodejs app, which speaks with the nodes through gRPC protocol.

You are on your way to become a blockchain developer!

If you have any questions, you can contact me at

Gaurang Torvekar

Written by

CEO at | @Ethereum Developer