Hyperledger Fabric v2.1 Installation Guide — Prerequisites & Bring up the Test Network

Burakcan Ekici
Coinmonks
7 min readApr 26, 2020

--

In this story, we will install Hyperledger Fabric v2.1 on the Linux machine. Everything may be hard when starting the new topic, so I try to collect all you may need in this story.

Let’s start from install the prerequisites which are clearly mentioned in here before Hyperledger Fabric installation;

  • Install Git: Install the latest version of Git with the command below.
  • Install cURL: Install the latest version of cURL with the command below.
  • Install wget: Install the latest version of wget with the command below. It will be needed for downloading Fabric binaries.
  • Install Docker and Docker Compose: Install the latest version of docker with the command below. Then you add your current user in docker group.
  • Install Go: Install and extract the 1.14.x version of go with the commands below. Then we carry go folders to under /usr/local directory.

We need to add our go path to the$PATH variable but what we add always be wiped when user login. To avoid executing the command at every time we log in, we open the .profile file which is located as $HOME/.profile write the export command to the end of .profile file.

  • Install Node.js & NPM: Download and install the Node.js and NPM with the commands below. We can install version 8 (8.9.4 and higher are supported) or version 10 (10.15.3 and higher are supported).
  • Install Python: Install version 2.7 of Python with the commands below. Also, the appropriate version is installing with node.js installation.

That’s all, we finally installed all we need and we will continue with the installation of the Fabric samples, binaries, and docker images.

Install Samples, Binaries and Docker Images

Now, we will install the Fabric samples, binaries, and docker images with the command below.

To install spesific release, we can pass the version identifiers to curl command such as the following rows.

The fabric-samples/bin folder keeps all of the platform-specific binaries you will need to set up your network and place them into the cloned repo and it looks like the image below after the curl command.

fabric-samples/bin folder

We can check the images with the command below.

Test the Hyperledger Fabric Network

Since we have successfully installed everything we need, we can deploy and test the Hyperledger Fabric Network by using the scripts.

  • Start the network: We go to the fabric-samples/test-network directory and start the network by using the script.
the expected output

In here, we may faced with the warning that is “Local fabric binaries and docker images are out of sync. This may cause problems” and the error that is “Fabric Docker image version of 1.4.6 does not match the versions supported by the test network.” looks like the following image.

To solve this problem, we firstly remove docker images and pull just images without cloning the repo and the downloading the binaries by executing the commands below. If everything is ok, we will have to see all the hyperledger docker images like below.

  • Create a channel: We can use the createChannel subcommand to create a channel between Org1 and Org2 join their peers to the channel.

If we don’t use -c flag, it creates the channel with default name mychannel so we can change the channel name with use the -c flag.

If the command was successful, we can see the message below.

the expected message
  • Deploy the chaincode: We can use the deployCC subcommand to deploy the chaincode.

The deployCC subcommand will install the fabcar chaincode on peer0.org1.example.com and peer0.org2.example.com and then deploy the chaincode on the channel specified using the channel flag. Since we created a channel with the default name mychannel, we no need any modifications.

By default, The script installs the Go version of the fabcar chaincode. As you see above, I used the language flag, -l, to install the javascript versions of the chaincode. The all Fabcar chaincode that wrote in different languages can be found in the chaincode folder of the fabric-samples directory.

With Hyperledger Fabric 2.0, the chaincode lifecycle has changed and deployCC subcommand provides chaincode to be installed, deployed, and invoked properly to that new lifecycle. In this story, I don’t mention it in detail. If you want to know more detail about this new lifecycle, you can look out this article.

Since invoking the initLedger function, the chaincode puts an initial list of cars on the ledger. As you see the code below, the initLedger function in fabcar chaincode and cars JSON array was filled. Then each one put to the ledger with await putState method.

If the chaincode is installed, deployed, and invoked properly you should see the following list of cars which is same above printed in your logs:

the expected output
  • Interacting with the network: Now we will use the peer CLI, which allows us to invoke deployed smart contracts, update channels, or install and deploy new smart contracts from the CLI. Here, we just focus to interact with our network. To add our binaries that we installed Install Samples, Binaries, and Docker Images section, we use the following commands.

After it, we can query the ledger from our CLI. The following command is used to query. It accepts function name which we want to query as the first argument so we can add parameters as an argument if the method we want to query needs it. We get the car information whose number is CAR9 by queryCar function.

Since we want to change an asset, we invoke the chaincode. When a network member wants to transfer or change an asset on the ledger, the chaincodes are invoked. With the following command, we change the owner of the car whose number is CAR9 by invoking the changeCarOwner function.

If the command has been executed successfully, you see Chaincode invoke successful. result: status:200message.

the expected output

After changing on an asset, we will check it on other peers by adding our binaries as we have done to Org1 peer and execute the following commands to define variables.

After it, we can query the ledger from our CLI as Org2 peer. The following command is used to query and we will see that the owner of the CAR9 was changed.

the information of CAR9

We have to down our network when we are finished using it by the following command.

That’s it, we have;

  • installed Prerequisites
  • installed Samples, Binaries, and Docker Images
  • brought up the test network
  • created a channel
  • deployed the chaincode
  • interacted the network

in this story.

Get Best Software Deals Directly In Your Inbox

v

--

--