Skip to content
Related Articles
Open in App
Not now

Related Articles

Hyperledger Fabric “Building Your First Network”

Improve Article
Save Article
  • Last Updated : 05 Dec, 2022
Improve Article
Save Article

Hyperledger Fabric is a Blockchain framework that works as the foundation for developing applications with a modular architecture. It is an open-source engine for blockchain and takes care of the most important features for evaluating and using blockchain for business use cases. Hyperledger comes under an open-source Umbrella Project under the Linux Foundation that helps in different fields of finance, banking, IoT, supply chain, manufacturing, and technology. This article focuses on discussing how to install Fabric-samples and how to “Build our First Network”.

Prerequisites for Hyperledger Fabric-Samples

In order to start the first Hyperledger fabric network Fabric-samples repository will be used. This repository is a set of CLI tool binaries and Fabric Docker Images that help you understand and use the basics of Fabric. Install the below dependencies before starting the project:

1. Install Docker

Installation on Windows: Visit the link to install the Docker setup on Windows. Hyperledger Fabric samples being used here are highly dependent on the bash script. So in windows where you need to install docker, it is recommended to use WSL2(Windows  Subsystem for Linux). You can directly install any Linux system of your choice through the windows store.

For WSL2 you need to ensure that the Docker desktop has enabled Integration so that WSL2 can Properly interact with the docker elements. you can do this by going into settings in docker desktop GUI and under the Resources tab you need to find wsl integration and ensure the checkbox for enable integration is checked.

Note:

In case if you are using wsl2 in windows you need to mount your local disk or alternatively you can use mnt command to temporarily mount your local disk at a time. 

Installation on Linux: Install the latest version of Docker if it is not already installed. Run the below command to install:

sudo apt-get -y install docker-compose

Installation on Mac: For macOS, it is recommended to use Homebrew to manage the prereqs.

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”

The Xcode command line tools will be installed as part of the Homebrew installation. Once Homebrew is ready, installing the necessary prerequisites is very easy:

Homebrew v3.x:

brew install –cask –appdir=”/Applications” docker

Docker Desktop must be launched to complete the installation so be sure to open the application after installing it:

open /Applications/Docker.app

2. Install Golang-go

Install the latest version of Go if it is not already installed (only required if writing Go chaincode or SDK applications).

Installation on Linux/Windows-wsl2:

sudo apt install golang-go

Installation on Mac:

brew install go@1.18.7

3. Install jq

Install the latest version of jq if it is not already installed (only required for channel configuration transactions).

Installation on Linux/Windows-wsl2:

sudo apt install jq

Installation on Mac:

brew install jq

4. Install Node/java

You can Install Node/java or use typescript to run the default queries present in fabric samples.

Installation on Linux/Windows-wsl2:

You can install the node in Linux/wsl2 using the below command:

npm install node

If needed for Linux you can install npm using the below command:

sudo apt install npm

Installation on Mac:

Install Node on Mac with the below command (npm will be installed with Node):

brew install node

5. Installing Fabric-samples Repository

To start out with fabric samples install the Fabric-samples bash script:

curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh

Then you can pull docker containers by running one of these commands:

./install-fabric.sh docker samples

./install-fabric.sh d s

To install binaries for Fabric samples you can use the command below:

./install-fabric.sh binary

Docker compose after running the script file

 

After that installing all the above-required binaries and docker-compose containers you can check the compose containers either through docker desktop or in the case of Linux you can use the docker ps -a command to check all available containers and their respective status.

Building First Network

Fabric samples by default provide a Test Network that we can use to run our first network. Follow the steps below to build the first network:

Step 1: Navigate through the Fabric-samples folder and then through the Test network folder where you can find script files using these we can run our network. The test network is provided for learning about Fabric by running nodes on your local machine. Developers can use the network to test their smart contracts and applications. It is recommended not to change the script file.

cd fabric-samples/test-network

Step 2: From inside this directory, you can directly run ./network.sh script file through which we run the Test Network. By default, we would be running ./network.sh down command to remove any previous network containers or artifacts that still exist. This is to ensure that there are no conflicts when we run a new network.

./network.sh down

Network down for first time

 

Step 3: Now you can bring up a network using the following command. This command creates a fabric network that consists of two peer nodes and one ordering node. No channel is created when you run ./network.sh up

./network.sh up

If the above  command completes successfully, you will see the logs of the nodes being created below picture:

Network Up for first time

 

Congratulation you have successfully run your first Hyperledger Fabric Network.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!