Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconBlockchain Technologybreadcumb forward arrow iconHyperledger Fabric Tutorial for Beginners: Comprehensive Guide

Hyperledger Fabric Tutorial for Beginners: Comprehensive Guide

Last updated:
24th Feb, 2021
Views
Read Time
8 Mins
share image icon
In this article
Chevron in toc
View All
Hyperledger Fabric Tutorial for Beginners: Comprehensive Guide

There are numerous Hyperledger frameworks and tools available. One of the most successful is Hyperledger Fabric. Since its release back in 2016, Hyperledger Fabric has become a popular framework for developing enterprise applications. In this Hyperledger Fabric tutorial for beginners, we will walk you through everything you need to know, right from what it is, what the structure is, and how to run your first application on it. Without any further delay, let’s begin with our Hyperledger Fabric tutorial.

Check out our free courses to get an edge over the competition.

What is Hyperledger Fabric?

Hyperledger Fabric is an enterprise-grade blockchain-based framework. It is an open-source framework that provides permission DLT (Distributed Ledger Technology) for developing applications and business solutions. Some of the core features of Hyperledger Fabric include:

  • Highly modular architecture
  • Plug-and-play consensus
  • Support for Solidity and EVM
  • Supports JSON queries, key-based queries, and other queryable data
  • Multi-language smart contract support

Check out upGrad’s Advanced Certification in Cyber Security 

Ads of upGrad blog

With the basic knowledge of Hyperledger Fabric and its core features, let’s move to the next part of this Hyperledger Fabric tutorial for beginners.

Learn Software Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

What is the Hyperledger Fabric System Architecture?

Before beginning with our core Hyperledger Fabric tutorial, it is essential to learn about the underlying architecture. Having a firm knowledge of the structure will help you understand how the framework operates.

  • Transactions: There are two types of transactions: deploy and invoke. The deploy transactions are used for creating chaincodes, which are programs run by the blockchain. On the other hand, invoke transactions are used to execute transactions in context with the previously deployed chaincodes.
  • Data structures: Like any blockchain framework, the data structures used in Hyperledger Fabric are in key-value pairs. The chain codes manipulate the data with the put and get operations.

Check out upGrad’s Advanced Certification in Cloud Computing 

  • Ledger: It is a sequence of all the successful and unsuccessful changes to the chain.
  • Nodes: They are the communication agents or, in other words, entities of a network.
  • Client: End-users or someone who acts on their behalf.
  • Peer: They handle the states of the chain and ensure everything runs smoothly.

Explore Our Software Development Free Courses

Hyperledger Fabric Tutorial for Beginners to Develop Their First App

Now since we know the basic architecture, it’s time to develop our first Hyperledger Fabric app.

Building and Launching the First Network

This step comprises installing prerequisites and sample components to initiate developing our app.

Building the Network

The first thing you need to do is build and launch the network. Without a running network, your app will be of no use. Check out Hyperledger Fabric’s prerequisite guide and binaries, Docker images, and sample installation guide.

Once everything is installed, use the following command to move to the repository with the sample network.

cd fabric-samples/first-network

Next, use the byfn.sh script to run the network. Running this network will facilitate network communication and launch the essentials like containers, peers, chaincode, etc., that will help with the other process. After running the sample network, it’s time to generate the artifacts.

Generating the Artifacts

Use the following code to generate the artifacts and then press “Y” when asked for confirmation to start filling in the necessary details.

.byfn.sh generate

Powering the Network

After generating the artifacts, you need to power the network. It will fire up all the components, including chaincode and containers, to allow new peers to join the network. Use the following code for powering the network:

./byfn.sh up

The default language for Hyperledger Fabric chaincode is Go. However, you can switch to using Node.js or Java by using the following commands respectively:

.byfn.sh up -l node

.byfn.sh up -l java

You can also opt for using multiple programming languages by using either of the following codes:

./byfn.sh up -o etcdraft

./byfn.sh up -o kafka

Launching the Network

Now we will be launching the network. But before that we have to:

  • get our application’s subdirectory
  • make a local clone of the fabric-sample repo

Use the following command script to launch the network:

./startFabric.sh javascript

After launching the network, you will have everything right from orderers to peers to certificate authorities for developing your application. Since we are using the application’s subdirectory, a smart contract will be auto-launched.

In-Demand Software Development Skills

Installing Your First Application

Use the following code to install the dependencies required for installing and initiating the application.

npm install

Connecting With Certificate Authorities

Once the network is up and running, let’s start by communicating with the authorities who can allow us to add users to the chain. To do this, we need to undergo the Certificate Signing Request (CSR). Use the below command to contact the certificate authority and create a public, private, and x.509 certificate.

node enrollAdmin.js

Your information will now be held in the wallet. Similarly, to add any new user, you need to go through the same process and use the following code:

node reisterUser.js

This code will add the user, and the details will be held in the wallet.

Querying a Ledger

You can use read queries to query a ledger through the blockchain network and get the results. The application won’t execute any write queries as ledgers are read-only.

Use the below code to retrieve all the data from the ledger:

node query.js

Next, we need to establish a connection to convey the data. After the connection is made, create a gateway to allow the application to connect to the network. The following line of codes will help you do all this.

const { FileSystemWallet, Gateway } = require(‘fabric-network’);

const gateway = new Gateway();

await gateway.connect(ccp, { wallet, identity: ‘user1’ });

const contract = network.getContract(‘subdirectory_name’);

The CPP in the above code is used to access and verify user information. The last line of the code is connecting to a particular channel. It is essential as the entire blockchain network runs on multiple channels.

Understanding the Contract

Head to the chaincode/subdirecory_name/javascript/lib subdirectory to access the application’s smart contract. In the above directory, the subdirectory_name will be the name of your application’s subdirectory. Open the application_name.js file you get here in an editor. In this file, you will get the smart contract and all the transactions defined within the Contract class. Suppose your application is about cars, the transaction details will look like:

async queryCar(ctx, carNumber) {…}

Read: Why Blockchain is the Future

Updating the Ledger

The last part of this Hyperledger Fabric tutorial for beginners is to update the ledger. Considering the same car example, let’s look at how you can add a new car in the log. Use the following line of code to add a new vehicle to the ledger.

await contract.submitTransaction(‘createCar’, ‘CAR15’, ‘Owner’, ‘Brand’, ’CarModel’, ‘Color’);

Using the above command will create a new car along with the mentioned attribute values. To send this new transaction to the ledger, write the below code:

node invoke.js

Ads of upGrad blog

This will successfully update the ledger.

Explore Our Software Development Free Courses

Conclusion

That brings us to the end of our Hyperledger Fabric tutorial. Blockchain technology and Hyperledger Fabric framework have the potential to revolutionize multiple industries across the world. This tutorial gave a brief idea of how the Hyperledger Fabric framework works and how to run your first transaction and app on it. If you want to get into the details and learn how to develop actual business applications using the framework, you can apply for upGrad and IIIT Bangalore’s Advanced certificate program in blockchain technology course.

The course 250+ hours of learning material in blockchain technology and frameworks like Ethereum, Hyperledger Fabric, Distributed Application Development(smart contracts development, backend development, API). If you want to pursue a career in blockchain development, go ahead and apply today.

Profile

Mayank Sahu

Blog Author
Mayank Sahu is the Program Marketing Manager with upGrad for all emerging technology vertical. His past experience is in analytics industry extensively in healthcare Domain. Mayank has completed his Graduation from IIT Delhi.
Get Free Consultation

Select Coursecaret down icon
Selectcaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Popular Blockchain Course

Frequently Asked Questions (FAQs)

1What is a Hyperledger bevel?

Hyperledger bevel is a type of decorative molding found in architecture. It is a simple but elegant design that is used to add a touch of sophistication to a structure. It is a blockchain platform that enables businesses to build and deploy blockchain applications. It is a part of the Hyperledger family of projects, and it uses the IBM Blockchain Platform. Hyperledger Bevel allows businesses to create and manage blockchain networks and deploy and manage blockchain applications on those networks. It also provides features for identity management, asset management, and smart contract execution.

2 Why should I specifically use Hyperledger fabric?

Hyperledger Fabric is a flexible platform with a wide range of business applications. Developing new applications, testing and developing prototypes, creating private or consortium blockchains, providing a foundation for smart contracts, streamlining the process of creating and managing digital identities, and enabling the exchange of data and assets between businesses are just a few of the most common applications. Hyperledger Fabric is also well-suited to the development of decentralized apps, which run on a network of computers rather than on a single server. This improves their security and resilience, as well as their scalability.

3How useful is blockchain in archeology?

Blockchain technology is being used in archeology to create a more transparent and efficient system for recording and managing archeological data. Blockchain allows for the secure and transparent sharing of data between archeologists and other stakeholders, such as museums and heritage organizations. It also enables the tracking of the provenance of artifacts and data, which helps to prevent fraud and theft. It could also be used to create digital archives of archeological data that can be accessed by the public. Similarly, blockchain could be used to develop a system for issuing and tracking digital certificates of authenticity for archeological artifacts. While still in its early stages, blockchain can revolutionize the field of archeology.

Explore Free Courses

Suggested Blogs

Top 12 Highest Paying Blockchain Jobs in India [A Complete Report]
900512
Blockchain is an emerging job skill in the IT industry. Technological advancements are gradually bringing this distributed ledger technology to the ma
Read More

by Mayank Sahu

19 Feb 2024

Skills Needed to Become a Blockchain Developer
53928
Blockchain development is one of the fastest-growing sectors. Companies are looking for blockchain developers to make new implementations, advance the
Read More

by Mayank Sahu

Prerequisites to Learn Blockchain Technology: It’s Not What You Think It Is
54173
There has been a massive development in the field of Blockchain technology in the last decade. Many people and companies came to know about Blockchain
Read More

by Mayank Sahu

16 Feb 2024

Blockchain Developer Salary in India 2024 [For Freshers & Experienced]
902392
The Blockchain Era is has arrived, and it is now. Enterprises across various sectors of the industry are warming up to the concept of the decentralize
Read More

by upGrad

11 Feb 2024

Top 10 Interesting Blockchain Project Ideas for Beginners/Students [2024]
176446
Summary: In this Article, you will learn top 10 interesting blockchain project Ideas for beginners. Trusted Crowdfunding Platform Using a Smart Cont
Read More

by upGrad

14 Jan 2024

Blockchain Applications in Supply Chain
5634
The distributed-nature technology of Blockchain has disrupted many industries, with its uses and blockchain applications in supply chain leading to in
Read More

by Radhika Maloo

28 Aug 2023

Applications of Blockchain in Healthcare Industry
6567
After taking the finance and business sector by storm, Blockchain applications in healthcare are now all set to radicalize the healthcare industry. Ev
Read More

by Shubham Chakraborty

23 Aug 2023

What is Ripple Blockchain? Everything You Need to Know in 2024
7172
Ripple is a popular name in the tech industry. And Ripple blockchain has created a lot of buzzes. We all know how blockchain is transforming the indus
Read More

by Mayank Sahu

21 Aug 2023

How Blockchain in Transforming Manufacturing Industry [2024]
6144
How Today’s Large Scale Industries Leverage Blockchain to Scale Their Manufacturing Process As a foundation for distributed ledgers, blockchain is an
Read More

by Mayank Sahu

26 Jun 2023

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon