Getting Started with Hyperledger Fabric
What is Hyperledger Fabric?
Hyperledger Fabric is an open-source blockchain framework under the Linux Foundation for developing distributed ledger solutions. It's used to build blockchain-based applications, networks, and products for private enterprises.
Sounds boring? Alright! Let's imagine Hyperledger Fabric as the superhero of the blockchain world – the caped crusader against the chaos of traditional databases. Picture it wearing a suit made of interconnected blocks, each carrying the power of unbreakable security and transparency. It's the Dark Knight of Distributed Ledger Technology unlike other superheroes of Blockchain like Bitcoin and Ethereum it ensures that transactions are not only secure but also private, like a business meeting in the Batcave. This is why Hyperledger Fabric is called a private or permissioned blockchain allowing it to add peers or members of that particular network so that villains of Gotham City cannot mess with any sensitive data. Instead of a utility belt, Hyperledger Fabric has a toolbox filled with smart contracts – its superpowers for automating and enforcing agreements. It's like having Alfred, the faithful butler, but for business processes. Need a contract executed flawlessly? Hyperledger Fabric's got it covered!
In a nutshell, Hyperledger Fabric is the blockchain superhero for every enterprise or business call. It's the hero businesses deserve, and the one they need right now in the ever-evolving landscape of digital transactions.
Why should you learn about this Blockchain world vigilante?
Even though it has many use cases in supply chain management and others which you can look up here. It is the goto technology for large-scale enterprises due to its features like:
Permissioned Network
Provides features for managing and validating members, ensuring a trusted and authenticated network
Modular Architecture
Enables flexibility, letting users plug in their preferred components, such as consensus algorithms and membership services
Smart Contracts (Chaincode)
Allowing for programmable and self-executing business logic
Privacy and Confidentiality
Communication between certain network members, ensuring confidential transactions within defined groups
High Performance and Scalability
Being deployed on the cloud can handle a serious amount of transactions per second.
Identity Management
Secure and authenticated interactions among participants
Interoperability
Easier for different systems and applications to integrate with the blockchain network
Pluggable Consensus
tailoring the network to specific requirements
The list of benefits is extensive. You might be wondering, "Yes! I understand it has many features and solutions for business problems, but what's in it for me?"
To be honest, it's hard to fully explain in a blog. But to start, you gain access to a community of developers collaborating in open source to support your journey in learning and mastering blockchain. You can also participate in The LFX Mentorship Program, where organizations like the Hyperledger Foundation personally mentor aspiring blockchain developers to create high-quality solutions and establish valuable, supportive connections. I'm also a mentee in this program, and I'll share more about my experiences and how you can join this amazing community in another blog soon! But if you do not like to wait and also want to become a mentee and a part of this wonderful community, you can start right now by going to this website and choosing a project under Hyperledger Foundation.
The Hyperledger Foundation has numerous projects developed by well-known companies, not just Hyperledger Fabric. Discover more about these companies by clicking here. Want to impress everyone at the blockchain party? Share your knowledge of Hyperledger and you'll have everyone's attention. Who needs party tricks when you can discuss consensus algorithms and distributed ledgers? So go ahead, learn some exciting new technologies and you may just receive a lucrative job offer in your inbox if you put in the effort.
If the starters didn't satisfy you yet and you want to have lunch on LinkedIn, feel free to ping me anytime. I'm always eager to discuss blockchain, especially Hyperledger :) But for now, let's delve into the technical side of it.
How does this even work?
To get a clear picture and an overview you need to understand some key concepts regarding hyperledger fabric which I will try my best to simplify and keep short and fun so that you understand the basics and can learn in-depth about them later from the documentation.
Key Concepts
Channel:
Channels are a method for establishing private and secure communication routes within a blockchain network. They allow a portion of network participants to conduct transactions and exchange information without requiring every participant in the network to be informed of or have access to those transactions. For instance, in a classroom, there may be multiple students in the same class, but they can create their own group or network with individuals who share similar interests and communicate with them without needing to divulge information to the entire class. These groups function as channels within the network.
Peers and Orderers:
A Fabric blockchain network consists of peer nodes, which store and manage copies of ledgers and smart contracts. Peers act as friendly neighbors in a bustling neighborhood, maintaining the community ledger and ensuring everyone is on the same page. These peers are components of an organization or consortium, allowing multiple organizations to interact and maintain information through a ledger.
Hyperledger Fabric uses an orderer node to add consistent data to the ledger. This ordering node, along with other orderer nodes, forms an ordering service that guarantees final and correct blocks validated by the peer. Unlike other distributed and permissionless blockchain networks, Fabric's design prevents ledgers from forking thanks to its deterministic consensus algorithms.
Ledger:
If you're familiar with blockchain, you likely know about ledgers. In simple terms, it's a record book storing data of a company's tangible and intangible assets, be it a sleek Tesla Car or information related to its new EV technology. It all depends on how you utilize it!
However, what sets hyperledger apart is its approach to the blockchain and the world state.
Blockchain: A transaction log recording all changes resulting in the current world state.
World State: A database containing the current values of a set of ledger states. The world state enables direct access to the current value of a state, rather than needing to calculate it by traversing the entire transaction log. Making it the Macqueen of ledger technologies.
Identities and Membership Service Provider (MSP):
While it may be exciting for us to have early access to the new EV technology, Elon Musk may not share the same enthusiasm. He prefers to work with trusted participants to build his business, and this is where Identities and MSP shine.
Elon Musk now has the ability to determine the specific type of engineers he requires for his team, both internally and externally, with the assistance of an MSP. Even if an engineer from Ford Motors or any other competitor's mechanical engineer, Musk may not want them to work on his new vehicle. The MSP maintains a record of the valid type of identities for working on the project, as well as the permissions and roles Musk wishes to assign to them.
He can issue certificates to official members using a service called Certificate Authority, which issues X509 digital certificates. This allows the identity to securely identify themselves to the team over the network with the help of Public Key Infrastructure. This is why Hyperledger is considered a private blockchain, unlike Ethereum where everyone has access to information about the new trending NFT. In Hyperledger, sensitive business information is only accessible to valid members or peers of the network.
MSPs occur in two domains in a blockchain network:
Locally on a peer node (local MSP) defined on the file system of the node or user channel configuration, (channel MSP) channel MSPs define administrative and participatory rights at the channel level.
An organization is a logically managed group of members. Elon Musk can also divide his company into multiple organizational units, each of which has a certain set of responsibilities. What’s most important about organizations is that they manage their members under a single MSP. The MSP allows an identity to be linked to an organization. This is where the Organisational Unit(OU) comes into place. Additionally, there is a special kind of OU, sometimes referred to as a Node OU, that can be used to confer a role onto an identity. This is particularly useful when you want to restrict the members of an organization to the ones holding an identity with a specific Node OU role in it. Example: client, admin, peer, and ordered.
Policies:
A policy is a set of rules that define the structure for how decisions are made and specific outcomes are reached. To that end, policies typically describe a who and a what, such as the access or rights that an individual has over an asset. We can see that policies are used throughout our daily lives to protect assets of value to us, from car rentals, health, our homes, and many more. Similarly, Fabric uses policies so that organizations can access or update a Fabric network, and provide the mechanism to enforce those decisions.
Policies are one of the things that make Hyperledger Fabric different from other blockchains like Ethereum or Bitcoin. In those systems, transactions can be generated and validated by any node in the network. The policies that govern the network are fixed at any point in time and can only be changed using the same process that governs the code. Because Fabric is a permissioned blockchain whose users are recognized by the underlying infrastructure, those users can decide on the governance of the network.
Smart Contract and Chaincode Lifecycle:
From an application developer’s perspective, a smart contract, together with the ledger, forms the heart of a Hyperledger Fabric blockchain system. Whereas a ledger holds facts about the current and historical state of a set of business assets, a smart contract defines the executable logic that generates new facts that are added to the ledger. Smart Contract can be written in various languages such as Java, Go, and Javascript. A chaincode is typically used by administrators to group related smart contracts for deployment. A smart contract defines the rules between different organizations in executable code. After the code is written it is deployed to a channel using the chaincode lifecycle listed below:
First, Package the chaincode: This step can be completed by one organization or by each organization.
Then, Install the chaincode on your peers: Every organization that will use the chaincode to endorse a transaction or query the ledger needs to complete this step.
After it is installed, we need to Approve a chaincode definition for your organization: Every organization that will use the chaincode needs to complete this step. The chaincode definition needs to be approved by a sufficient number of organizations defined as per the policy
Finally, we need to Commit the chaincode definition to the channel: The commit transaction needs to be submitted by one organization once the required number of organizations on the channel has been approved. The submitter first collects endorsements from enough peers of the organizations that have approved and then submits the transaction to commit the chaincode definition.
After it is deployed applications can connect to the fabric network so that they can invoke a smart contract and perform business logic using SDKs to generate transactions that are recorded on the ledger. The flow of transactions happens like this:
Transaction Proposal:
A participant initiates a transaction by creating a proposal, specifying the action to be performed (e.g., transferring an asset).
Endorsement:
The proposal is sent to endorsing peers (selected participants) for approval.
Endorsing peers simulate the transaction and sign off if they agree.
Transaction Proposal Response:
The endorsed proposal returns to the participant along with the endorsements.
Ordering:
The endorsed proposal is submitted to the ordering service, which arranges transactions into blocks and establishes a consistent order for them.
Block Distribution:
The ordered blocks are distributed to all peers in the network.
Validation and Commit:
Peers validate the transactions in the block against endorsement policies.
If validation is successful, the transactions are committed to the ledger.
Notification:
Peers notify the participant and other relevant parties that the transaction is complete.
Update World State:
The world state, representing the current state of assets, is updated based on the committed transactions
Fabric Network Architechture
Now that we have all the musical instruments of Hyperledger Fabric, let's see how they perform together in the Network Orchestra.
In the image above, three organizations, A, B, and O, have collectively agreed to establish a network. This network includes a channel configuration that outlines the definitions of the organizations and the policies governing the roles each organization will play on the channel.
Within this channel, A and B will join as peers, named Peer A and B, while O will serve as the ordering service for the channel. All of these nodes will maintain a copy of the channel's Ledger, where transactions are recorded. Each peer is issued an identity by the certificate authority and validated by the MSP.
Once a chaincode is written, it can be deployed to the channel using the chaincode lifecycle, and the peers will host these smart contracts. The application developed by organizations A and B using SDKs can then utilize the chaincode hosted on their peer to execute transactions or update the ledger.
Where do I go from here?
It's easy. You can now go and install and run the fabric network from here. Once you're familiar with the network, you can explore the tutorials and try them out on your own. Then, you can join the hyperledger discord channel, look for projects you're interested in on GitHub, and become the open-source developer you've always wanted to be, or maybe find your own way!
Conclusion
Hyperledger Fabric is a vast topic, so I can't cover everything in this blog. My goal is to spark your interest in learning more about technologies like Fabric and provide an introduction to permissioned blockchains.
I also want to express my gratitude to my mentors Aditya Joshi and Nithin Pankaj for their fantastic guidance, to Ma'am Min Yu for overseeing the mentorship program, and to Hyperledger Foundation for giving me this amazing opportunity to learn and grow as an open source developer.
Thank you and Happy Coding :)
Subscribe to my newsletter
Read articles from Subhranil Raha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Subhranil Raha
Subhranil Raha
LFX mentee'23 @hyperledger | Smart India Hackathon '22 Finalist | Ex Google DSC Fullstack Lead | Ex-Intern @IEMLabs | Fullstack Blockchain DevOps