Blockchain basics: Hyperledger Fabric
Learn how to make the most of this versatile blockchain framework
Blockchain technology presents abundant opportunities for innovation. It has the power to revolutionize businesses by fundamentally changing the way business transactions are done.
So what’s the best way for developers to begin developing code for blockchain networks? I recommend starting with a firm grasp of the Hyperledger Fabric project.
Hyperledger is an open source collaborative effort created to advance cross-industry blockchain technologies for business use. This global collaboration is hosted by The Linux Foundation.
Hyperledger incubates and supports a range of blockchain business technologies, frameworks, libraries, and applications. The Hyperledger project hosts several blockchain frameworks, including Hyperledger Fabric. This article gives you an overview of what Hyperledger Fabric is, how to use it to build solutions, and how a transaction gets executed in Hyperledger Fabric.
What is Hyperledger Fabric?
Hyperledger Fabric is an open source framework implementation for private and permissioned business networks, where the member identities and roles are known to the other members. It’s designed as a foundation for developing solutions with a modular architecture. It allows components, such as ledger database, consensus mechanism, and membership services, to be plug-and-play. It leverages container technology and delivers enterprise-ready network security, scalability, and confidentiality.
A Hyperledger Fabric network has these components:
- Assets. An asset is anything that has value. An asset has state and ownership. Assets are represented in Hyperledger Fabric as a collection of key-value pairs.
Shared ledger. The ledger records the state and ownership of an asset. The ledger consists of two components:
- The world state describes the state of the ledger at a given point in time. It’s the database of the ledger.
- The blockchain is a transaction log history that records all transactions.
Smart contract. Hyperledger Fabric smart contracts are called chaincode. Chaincode is software that defines assets and related transactions; in other words, it contains the business logic of the system. Chaincode is invoked when an application needs to interact with the ledger. Chaincode can be written in Golang or Node.js.
- Peer nodes. Peers are a fundamental element of the network because they host ledgers and smart contracts. A peer executes chaincode, accesses ledger data, endorses transactions, and interfaces with applications. Some peers can be endorsing peers, or endorsers. Every chaincode may specify an endorsement policy, which defines the necessary and sufficient conditions for a valid transaction endorsement.
- Channel. Channels are a logical structure formed by a collection of peers. This capability allows a group of peers to create a separate ledger of transactions.
- Organizations. The Hyperledger Fabric network is built from the peers owned and contributed by the different organizations that are members of the network. The network exists because organizations contribute their individual resources to the collective network. Peers have an identity (digital certificate) assigned by a Membership Service Provider from its owning organization. Peers of different organizations can be on the same channel.
- Membership Services Provider (MSP). The MSP is implemented as a Certificate Authority to manage certificates used to authenticate member identity and roles. No unknown identities can transact in the Hyperledger Fabric network. It manages user IDs and authenticates all participants on the network which enables Hyperledger Fabric as a Private and Permissioned network.
- Ordering service. The ordering service packages transactions into blocks to be delivered to peers on a channel. It guarantees the transaction delivery in the network. It communicates with peers and endorsing peers. The supported configuration mechanisms for the Ordering service are Solo and Kafka.
Figure 1. The components of a Hyperledger Fabric network (for simplicity, channels are not shown)
How a blockchain solution works
In a blockchain solution, the Hyperledger Fabric network serves as a back end with an application front-end to communicate with the network. SDKs help you set up the communication between front and back end, such as the Node.js SDK and Java SDK. The SDK provides a way to execute user chaincode, perform transactions in the network, monitor events, etc.
To write a blockchain application, you need to:
- Write chaincode in a supported programming language like Go.
- Deploy chaincode on Hyperledger Fabric network.
- Develop a client application using an SDK.
How a blockchain transaction is executed
The high-level request flow of a transaction in a Hyperledger Fabric network goes like this:
- The client connects to a Hyperledger Fabric network using the Node.js or Java™ SDK. Using the SDK API, the client creates a transaction and sends it to the endorsing peer.
- The endorsing peer verifies the client’s signature, simulates a transaction, and sends an endorsement signature.
- If the transaction is endorsed, the client submits the transaction to the ordering service. Otherwise, the transaction is cancelled.
- The ordering service delivers a transaction to the peers. All peers commit and apply the same sequence of transactions and update their state.
Hyperledger Fabric is a blockchain framework implementation. IBM Blockchain solutions and Blockchain Platform as a Service on IBM Cloud both leverage Hyperledger Fabric. Now that you understand what Hyperledger Fabric is and how it works, you’re ready to start developing blockchain applications — so dive in and start experimenting!
Kick-start your blockchain network now with the IBM Blockchain Platform.
Check out the many blockchain code patterns on IBM Developer. They provide roadmaps for solving complex problems with blockchain technology, and include architecture diagrams, code repos, and additional reading.
Stop by the IBM Developer Blockchain hub. It’s your source for free tools and tutorials, along with code and community support, for developing and deploying blockchain solutions for business.