Hyperledger Fabric Tutorial For Beginners: Step by Step Guide


Back to New at Nirolution Hyperledger Tutorial Blog

Hyperledger Fabric Tutorial For Beginners: Step by Step Guide

In this Hyperledger Fabric Tutorial For Beginners we will show you how to learn everything you need to know about the Hyperledger Fabric. Afterwards you will be able to create a simple dapp. We explain what the Hyperledger Fabric is and why you should use it. After that I will explain the Hyperledger Architecture and develop a Hyperledger Application step by step.

“Hyperledger Fabric Tutorial For Beginners: Step by Step Guide” – Content:

  1. What is Hyperledger Fabric?
  2. Hyperledger Fabric Features
  3. Fabric Components
  4. Hyperledger Dapp Programming

What is Hyperledger Fabric?

Hyperledger Fabric is a private blockchain that helps companies to develop decentralized applications. So, it has a modular architecture that allows us to achieve a high level of privacy, flexibility, resilience and scalability. Thus, this allows us to develop apps for any industry with Fabric.
More than 40 organizations are now working together on the Hyperledger Fabric project. The goal is to develop the best enterprise framework on the market.

But why should you choose Hyperledger Fabric?
Fabric offers great DLT technology for companies. It has some great features that make it an ideal choice for a business. We’ll show you exactly what those features are.

Hyperledger Fabric Features

Fabric has 5 characteristics that make it one of the best frameworks for businesses.

Identity Management

Identity management is critical to most businesses. With Fabric you can ensure that authorization is clearly regulated.

Efficiency

Fabric is much more efficient than public blockchains. This is because network roles are assigned to nodes. In addition, transactions are performed separately from the engagement.

Modularity

Fabric offers a modular structure. This allows you to easily integrate other applications. You can also define the consensus, the algorithm, the identity, and much more.

Privacy

Hyperledger’s architecture offers you appropriate confidentiality and data protection. This means that you can use data channels where no information can be leaked.

Chain Code Contracts

Hyperledger Fabric offers you with Chain Code functionality to call up a certain type of transaction.

Hyperledger Components

Before we can start developing a Hyperledger Dapp, you first need to understand the components of Hyperledger Fabric. We also explain the data structure and all the important components.

System Architecture

Factory consists of many nodes that communicate with each other. These represent the entire network. So, there is also chain code that is executed by the blockchain. They store data and execute transactions.

Transactions

There are two types of transactions in Hyperledger Fabric.
Deployment transactions: You are responsible for creating a new chain code with parameters as a program. Then the chain code is installed on the blockchain.

Invoke transactions

This allows you to call transactions that have already been installed by chain code.

Data structures

The data in Fabric is structured according to the Key-Value-Store (KVS). The keys are usually names and the value is blobs. With the chain code you can change the data with the -Get and -Put option.

Ledger

The ledger is an overview of all successful and unsuccessful status changes. It therefore consists of ordered blocks containing transaction arrays.

Nodes

Nodes can be any communication unit within the network. This includes computers, laptops or even mergers of Pcs.

Client

A client is someone who can act as an end-user.

Peers

Peer handles the state of the ledger. They also ensure that the network operates optimally. Peers can be supporting peers, which helps to advocate a transaction.

Hyperledger Dapp Programming

Now that we have discussed all the important components, we can now develop our Hyperledger Dapp. You will learn how to handle Smart Contracts, Chain Code and other applications within the framework.
First, we have to set up a development environment. You need this to make sure your app has the necessary network available. You also need it to execute Smart Contracts.

Install Hyperledger

Before we can start, we first have to install the right development environment.
Here you can find everything you need for the installation.
The Hyperledger Composer guide can also help you.
If you have installed everything correctly, you will get a “fabric-samples” repository.
To change to this directory, type the following into the CD command line:
cd fabric-samples/first-network
To get started with the project, you need to use the script byfn.sh This allows you to start the project with four peers. Each of them represents two different organizations. It also starts the required containers, chain codes and transactions.

Generate Certificates

You can now generate the certificates and keys for the network. To do this you have to execute the following command.

.byfn.sh generate

You must then press Y to supply the network with the required information.

Powering Hyperledger

Next, we need to power the network. To do this, you must enter the following command:

./byfn.sh up

Then the framework will compile the chain code images. Additionally, the containers are also available to allow new peers to join the network.
For Fabric, Go is used as the default language for the chain code. But Node.js and Java are also supported. To switch to Node.js enter the following:

.byfn.sh up -l node

And for Java:

.byfn.sh up -l java

Now we can start the network.
To start the network, we enter the shell script startFabric.sh. Now we have a network with all important components.

Install Hyperledger Classes

Now we have to install all the important classes. For this we enter npm install. This will install the following:

fabric-network class → enables transactions, identities, wallets
fabric-ca-client → users are registered with their respective certification authorities

Register Users

Now that the network is up and running and we have installed everything important, we can register a user.
First, we will register the admin. To do this, the admin must have the certification authority create a public, private and X.509 certificate. For this you have to enter the following:

Node enrollAdmin.js

If you want to register another user, you need:

Node registerUser.js

Blockchain Connection

Now we need information from the blockchain.
You can easily connect your database with the blockchain.
You can do this with:

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

With the following code you create a gateway to connect the applications to the network.

const gateway = new gateway();
await gateway.connect(ccp, { wallet, identity: 'user1' });

The ccp is used to identify the user and the associated wallet information. Since Hyperledger Fabric runs on different channels, it is important to connect to the correct channel.

const contract = network.getContract('fabcar');

Hyperledger Chain Code

Now we need Smart Contracts. For this, we need to understand how to execute queries and update the ledger.
To create a Smart Contract we need to know the different classes.
To do this you have to go to the directory chaincode/fabcar/javascript/lib. Then open fabcar.js in your editor. Here you will find the classes to define the Smart Contract.
A transaction could look like this:

async queryHouse(ctx, houseNumber) {...}

Updating Hyperledger

Now that we have bought a house with the Smart Contract, we still have to update the ledger.
For this we first create a new house. For this we need the invoke.js function. Open the file and enter the following:

await contract.submitTransaction('createHouse', 'MyHouse, 'Size', 'Color', 'Owner');

This calls the app createHouse Smart Contract transaction. You get the house with all information. Now we have to update the ledger. We do that with this:

node invoke.js

Now you have your first simple hyperledger app that allows you to interact with the blockchain. Based on this simple guide, you can develop real life applications, that the market needs.

Do you like our Hyperledger Fabric Tutorial For Beginners? If you want to be informed about the latest updates, follow us on Facebook, Pinterest and Steemit.

Stay current on your favorite topics

Leave a Reply

Close Menu