Header Ads

Building Blockchain Network From Scratch Using Hyperledger - Part 1 [Tutorial]

Hyperledger Fabric is an open source blockchain framework that is used for developing private blockchain business networks which is a result of contribution by Digital Asset and IBM during the first hackathon. It allows components membership services, plug-n-play, and consensus. The Hyperledger application network is built on a framework, where fabric serves as backend and client-side application acts as front-end. Currently, SDKs are available for Node.js and Java while the future is directed toward application development using Python and Golang support too.

Before We Start

In this article series, we would learn the steps to build a blockchain application from scratch. Before starting, please note that Hyperledger Fabric only runs on Unix-based operating systems and so, you would need to set up a Virtual Machine running Unix if you are working on Windows operating system. As part of our Blockchain development, we expect that you are familiar with Java-scripting. For our client side, we will set up a REST API server and use Angular to leverage REST API to interface with the network.


Hyperledger Fabric networks are created by using javascript based tools and scripts which are incorporated in Hyperledger Composer. Broadly, the composer is used to generate three components Business network Archive (BNA), Composer Playground & Composer REST Server.

Business Network Archive

The composer is used to package the required files with which an archive is generated, this archive is then deployed to the fabric network. Let us look what all files are needed to be included in a BNA.
  1. Access Control Limitations: This is a file that contains information on the rules which define the authorization of participants in the network. These rules contain information on the assets and other such components that can be controlled by participants.
  2. Business Logic: This file contains the logic for transaction functions.
  3. Network Model: This is the repository that houses definition of resources present in the network, including, participants, assets, and transactions.
  4. Query File (Optional): This file includes all the queries that need to be run on the network. They are similar to an SQL query, an instance can be a query written to return all drivers from default registry whose age is less than a specified parameter or the name start with the letter ‘A’

Composer Playground

Once the model is built, it can be tested on a web-based user interface, this UI is introduced by Composer Playground component. Apart from testing business scenarios, it is used to model proof of concepts by using the browser’s local storage to simulate the blockchain network. Also, a local fabric runtime on a deployed network can be accessed using the playground component. In such case, the network is not simulated by the playground as it communicates with local Fabric runtime directly.

Composer REST Server

This tool gives the flexibility to generate a REST API server. This API server can be used by the client application and used to integrate other non-blockchain applications in the network.


Now since we have a picture of how to go forward with building the blockchain network, we have to be clear with the prerequisites before we actually start to build the application.

Installing Prerequisites

To run Hyperledger Fabric and Composer the minimum requirement is to have at least 4GB of memory. Also, the Hyperledger Composer can be installed on Ubuntu or MacOS. The below-mentioned components are to be installed as a part of prerequisites :
  1. Docker Engine and Docker Compose
  2. Nodejs and NPM
  3. Git
  4. Python 2.7.x
Though Mac users have to install all the aforementioned prerequisites manually and validate the installation, for Ubuntu users, the Hyperledger’s bash script makes the process easy by running the following script :

Installing Tools

A set of commands need to be run to the system’s terminal to install the tools. These commands are extremely crucial and sudo should not be used while running the npm commands.

Here, the first installation is for composer-cli which will act as the most crucial package. The rest are important but not essential for starters but these components will be needed as the requirements grow and the learning increases.

Installing local Hyperledger Fabric runtime

Let us start directly with the commands that are needed for the installation, and later we will go through what each of them to understand what actions they perform.

The first step is to make a new directory with mkdir and then browse to it with the change directory command. The downloadFabric.sh downloads and extract the tools that are required to install Hyperledger Fabric in the newly created folder.

Then the fabric version needed is specified, here hlfv12 specifies the version being installed is 1.2. After, the required version is installed a PeerAdmin card should be generated. This is analogous to the business cards in real life, all participants in a fabric network have business cards. The participant holding the PeerAdmin business card has the authority for the private blockchain, these participants have authority to deploy, manage, and delete the business networks on the Fabric runtime.

Once the PeerAdmin business cards are made the below screen is displayed showing the connection profile and the userID having the PeerAdmin card to that profile.

On typing ls the below screen is displayed which shows various scripts and processes which are running as a result of the downloading and starting the fabric.

The fabric can be stopped using the command ./StopFabric.sh, and once the development session is completed ./teardownFabric.sh should be executed.

The above statement is executed because the local runtime is for development use and has to be frequently started, stopped or torn down. A persistent state can be achieved if the network is deployed outside dev. This can be done on managed IBM platform or Kubernetes.

This blog has come to a wrap, now that we have learned basics of Hyperledger Fabric and pre-requisites required to deploy an application, in the next blog we will see how to create and deploy a business network.

Happy Coding!