Blockchain basics: Hyperledger Fabric and Hyperledger Composer
What's the difference?
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 two open source Hyperledger projects: Hyperledger Fabric and Hyperledger Composer. The names are similar, but knowing the difference is key to getting started with blockchain development.
“Spoiler alert: Both are open source Hyperledger projects. One is a cool development tool, and the other is the powerful engine of business blockchain networks.”
Both projects are under the Hyperledger umbrella. Hyperledger is an open source collaborative effort created to advance cross-industry blockchain technologies for business use. It's a global collaboration, hosted by The Linux Foundation.
The Hyperledger projects include blockchain frameworks, such as Hyperledger Fabric, and related developer tools, such as Hyperledger Composer, which simplify the creation of blockchain networks and applications.
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, 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-end and back-end, such as the Nodejs 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 Nodejs 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.
What is Hyperledger Composer?
Hyperledger Composer includes these components:
- Business network archive
- Hyperledger Composer Playground
- REST API support
Business network archive
- Network model file (.cto). As part of your business network model, you define the assets as well as the transactions and participants that can interact with those assets. The model file contains definitions of assets, participants, and transactions.
- ACL file (.acl). This file contains the access control rules that define the rights of the different participants in the business network.
- Query file (.qry). This file defines the query that can run in a network.
Figure 2. The components of a business network definition that can be deployed to a network and accessed by applications
Hyperledger Composer Playground
Hyperledger Composer also provides a web-based user interface called "Playground" that you can use to model and test your business network. The Playground uses your browser's local storage to simulate the blockchain network's state storage. Because it doesn't need a running blockchain network, it's an excellent starting point for your proof-of-concepts.
REST API support
Hyperledger Composer also generates REST APIs based on the business network definition using a LoopBack connector. These REST APIs can be easily consumed by client applications and integrate with non-blockchain applications.
In a nutshell, Hyperledger Composer is the application development framework for building blockchain applications based on Hyperledger Fabric. In other words, Hyperledger Composer helps you create business network definitions, which you deploy to Hyperledger Fabric, where they run.
- Learn more about creating
business networks from scratch using Hyperledger Composer in our
popular series, Hyperledger Composer basics, by Steve
- Try the new IBM Blockchain Starter Membership Plan.
It gives you an economical way to kick-start
a blockchain network where
you can easily deploy and test sample blockchain
applications. You can also deploy your business network model
that you create using Hyperledger Composer, as described in this
article, to run on the Starter Plan.
- Stay in the know with the monthly Blockchain Newsletter for
developers. Check out the current issue and subscribe.
- Check out the many code patterns, which provide roadmaps
for solving complex problems with blockchain technology, and include
architecture diagrams, code repos, and additional
- Stop by the Blockchain Developer Center. It's your source for free tools and tutorials, along with code and community support, for developing and deploying blockchain solutions for business.
- A deep dive into Hyperledger Fabric architecture
- An introduction to Hyperledger Composer
- What is Hyperledger?