Introduction to Hyperledger Fabric: Unraveling the Potential of Private Blockchain Technology

Shahroz Abbas
CoinsBench
Published in
3 min readApr 15, 2024

--

Hyperledger Fabric is a private blockchain framework that is built in a modular architecture way where each component is linked to the other. The working of Hyperledger fabric is very different from the public blockchains where only miners can mine the block. The concept of Hyerledger fabric is based on Practical Byzantine Fault Tolerance (PBFT) and this eliminates the need for resource-intensive mining activities.

Fabric is designed to provide businesses a solutions on scalability, privacy, and flexibility. As the ledger in the public blockchain is accessible to all the peers connected to the network, therefore, Businesses need privacy and they cannot rely on the public blockchain.

Fabric is divided into modules therefore it consists of different components and those components are:

  1. Peers: Peers are the clients(computers) connected to the network. These peers are responsible for maintaining the ledger, executing chain-code (smart contracts), and endorsing transactions.
  2. Fabric-CA: Fabric CA (Certificate Authority) plays a crucial role in the Hyperledger Fabric ecosystem. Fabric CA generates and distributes digital certificates to network entities and then by using these certificates they are registered into the MSP.
  3. MSP: Membership Service Provider(MSP) is used to register the peers and maintain the identity of each peer. Without being registered into the MSP, the peers(clients) can’t access the ledger.
  4. Orderer: The Orderer is responsible for ordering the number of incoming transactions. It accepts the number of transactions for a certain period of time(Time specified in the config file) and makes a block of those transactions after ordering the transactions and sends that block to the committer.
  5. Channel: The Channel is the private communication between specific network peers. Each peer needs to join the channel inorder to access ledger and communicate with the other peers connected to the channel
  6. Chaincode: Chaincode, also known as smart contracts, encapsulates business logic and defines transaction rules within the Fabric network. These chaincode could be written in various programming languages to suit diverse development preferences and requirements.

We are using the Fabric 2.2 version and assuming that you already have installed git, curl, docker and docker-compose.

Assuming that you are in test-network folder:

Setting Up Environment Variables Org1:

Set the environment variables that allow you to operate the peer CLI as Org1.

export CORE_PEER_TLS_ENABLED=true

export CORE_PEER_LOCALMSPID=”Org1MSP”

export PATH=$PATH:$PWD/../bin/

export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Or

Setting Up Environment Variables Org2:

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID=”Org2MSP”

export CORE_PEER_ADDRESS=localhost:9051
export PATH=$PATH:$PWD/../bin/
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Turning up the network:

./network.sh up

This command will turn up the network with 2 peers on boards from 2 organizations which are org1 and org1.

Creating the channel:

./network.sh createChannel

This command will create a channel with a default name which is mychannel. If you want to change the channel name then add -c with the channel name.

Deploy Chaincode:

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript -ccl javascript

This command deploys chaincode onto a Fabric network which is based on the javascript language.

Invoke Chaincode:

peer chaincode invoke -o localhost:7050 — ordererTLSHostnameOverride orderer.example.com — tls — cafile “${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem” -C mychannel -n basic — peerAddresses localhost:7051 — tlsRootCertFiles “${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt” — peerAddresses localhost:9051 — tlsRootCertFiles “${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt” -c ‘{“function”:”InitLedger”,”Args”:[]}’

This command is used to invoke the chaincode.

Query:

peer chaincode query -C mychannel -n basic -c ‘{“Args”:[“GetAllAssets”]}’ | jq

This command is used to query all the ledger inside the chaincode.

Conclusion:

In conclusion, Hyperledger Fabric presents a robust solution for businesses seeking a private blockchain framework. Its modular architecture allows businesses to customize their blockchain networks to suit their specific needs, promoting flexibility and scalability. Fabric’s emphasis on privacy, achieved through private channels and identity management via Fabric CA and MSP, makes it particularly suitable for sensitive business applications.

--

--