Categories: BlockChainHyperledger

Hyperledger Fabric – Hello World with Blockchain Network

Hyperledger Fabric Hello World is about building your first blockchain network. We will make use of fabric-samples provided by Hyperledger. The first Blockchain network will be built using Docker containers. The first network will result in running containers representing some of the following:

  • Two peer nodes each, representing two different organizations. Thus, one organization will have two peer nodes, one of which is called an anchor node and is used to ensure availability. For two organization, there will be four nodes.
  • One node representing Ordering service
  • Management node to do some of the following activities:
    • Join peers to a channel
    • Deploy and instantiate chain code
    • Drive execution of transactions against deployed chain code

The key point to note that the Hyperledger Fabric executes blockchain transactions within a channel. If the channel name is not provided, a default channel name such as mychannel is used.

Install pre-requisites

  • Make sure the pre-requisites are installed. Some of them are following:
    • cURL; For Windows, install Windows extras
    • Docker and Docker Compose
    • Go Programming language
    • Nodejs runtime and NPM
    • Install Python (v 2.7)
      The details can be found on this page, Install prerequisites.
  • Download and install Hyperledger fabric samples.
    • This will install samples within a folder, fabric_samples.
    • Go to folder, hyperledgerRootFolder/fabric_samples/first-network.
    • Execute command such as following to ensure the readiness:
      ./byfn.sh -h
      

      Execution of above command would show following on sole:

      Figure 1. byfn.sh execution

Generate Network Artifacts

  • Execute command such as following to generate network artifacts:
    ./byfn.sh -m generate
    

    Above command does some of the following:

    • Generate certificates and keys for different network entities
    • Create genesis block for bootstrapping the ordering service
    • A set of configuration transactions required to setuset uphannel.

Bring up the Blockchain Network

Execute the following command to bring the Blockchain network up and running.

./byfn.sh -m up

Following happens as a result of bringing up the network:

  • First and foremost, a channel is created with a default name, mychannel. Following diagram represents the screenshot related with creation of the channel.

    Figure 2. Create Hyperledger Channel

  • The second step is to have all the peers join the channel.

    Figure 3. Peer Nodes join Hyperledger Channel

  • Next step is to update the anchor peers for both the organization
  • With above, peer setup is done. Now, it is time to install the chaincode on some of the peer nodes.

    Figure 4. Hyperledger Fabric Install Chaincode

  • Finally, chaincode queries are sent to peer node and transaction are executed.

Bring down the Blockchain Network

Following command can be executed to bring down the network

./byfn.sh -m down

Figure 5. Hyperledger – Bring Down Blockchain Network

Sneak Peek into Docker Containers for Blockchain Network

Following represents the docker containers which got started to bring up the network:

  • Two peer container nodes each for two organization
  • One ordering service container node
  • One container node for fabric tools, CLI
  • Container nodes for chaincodes

Figure 6. Hyperledger Fabric Blockchain Network with Containers

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

Share
Published by
Ajitesh Kumar

Recent Posts

Mean Squared Error vs Cross Entropy Loss Function

Last updated: 28th April, 2024 As a data scientist, understanding the nuances of various cost…

2 days ago

Cross Entropy Loss Explained with Python Examples

Last updated: 28th April, 2024 In this post, you will learn the concepts related to…

2 days ago

Logistic Regression in Machine Learning: Python Example

Last updated: 26th April, 2024 In this blog post, we will discuss the logistic regression…

4 days ago

MSE vs RMSE vs MAE vs MAPE vs R-Squared: When to Use?

Last updated: 22nd April, 2024 As data scientists, we navigate a sea of metrics to…

5 days ago

Gradient Descent in Machine Learning: Python Examples

Last updated: 22nd April, 2024 This post will teach you about the gradient descent algorithm…

1 week ago

Loss Function vs Cost Function vs Objective Function: Examples

Last updated: 19th April, 2024 Among the terminologies used in training machine learning models, the…

2 weeks ago