Contents


Blockchain basics: Hyperledger Fabric and Hyperledger Composer

What's the difference?

Comments

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)
Diagram of the components of a Hyperledger Fabric                     network
Diagram of the components of a Hyperledger Fabric network

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:

  1. Write chaincode in a supported programming language like Go.
  2. Deploy chaincode on Hyperledger Fabric network.
  3. 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:

  1. 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.
  2. The endorsing peer verifies the client’s signature, simulates a transaction, and sends an endorsement signature.
  3. If the transaction is endorsed, the client submits the transaction to the ordering service. Otherwise, the transaction is cancelled.
  4. 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 is a set of JavaScript-based tools that simplify and expedite the creation of Hyperledger Fabric blockchain applications. Using Hyperledger Composer, business owners and developers can quickly create chaincode (business logic) and blockchain applications. Instead of writing chaincode in Golang, you'll generate a business network archive (.BNA) file for your network, as described below.

Hyperledger Composer includes these components:

  1. Business network archive
  2. Hyperledger Composer Playground
  3. REST API support

Business network archive

Hyperledger Composer helps you model your current business network, including your existing assets and the transactions related to them. To generate the business network definition, Hyperledger Composer requires a network model file, JavaScript file (.js), access control file (.acl), and query file (.qry).

  • 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.
  • JavaScript file (.js). This file defines the transaction functions.
  • 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.

Using these files, Hyperledger Composer creates a business network definition that can be packaged up and exported as an archive. The exported archive file is a Business Network Archive (.bna) file, which you can deploy on an existing Hyperledger Fabric network. The BNA file contains executable transaction processor functions and can be considered as a smart contract written in JavaScript. You can write client applications using Hyperledger Composer APIs to access BNA functions.

Figure 2. The components of a business network definition that can be deployed to a network and accessed by applications
Diagram of the components of a business network definition that can be                     deployed to a network and accessed by applications
Diagram of 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.

Summary

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.

The beauty of Hyperledger Composer is that it provides a high-level abstraction layer that you can use to model your business network, write JavaScript functions for transactions, and expose those functions as as REST APIs for client application development. Because minimal programming is required, business owners who are not necessarily application developers can easily model and write transaction functions for blockchain networks.

Next steps

  • Learn more about creating business networks from scratch using Hyperledger Composer in our popular series, Hyperledger Composer basics, by Steve Perry.
     
  • 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 reading.
     
  • 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.

Learn more


Downloadable resources


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Blockchain, Cloud computing, Open source
ArticleID=1061939
ArticleTitle=Blockchain basics: Hyperledger Fabric and Hyperledger Composer
publish-date=07012018