How to develop Blockchain Application with Hyperledger Fabric?
Nowadays, everyone across the world is talking about the distributed ledger technologies and how it can transform various industries. The secure and distributed architecture of blockchain makes it a suitable technology for the enterprise mobile/web apps. Organizations which use mobile/web apps to store transaction data and interact with customers can benefit from blockchain integration. Let’s discuss some of the use cases where organizations can develop blockchain application to improve business operations.
- Supply Chain Management
Enterprises can integrate blockchain in mobile apps to make it easier to trace the product’s movements and history from production to sales. Also, consumers can access transaction details like change orders, serial numbers, quantities, warehousing specification, quality and shipment notifications with an app integrated with blockchain.
LeewayHertz Live Project: TraceRx
- Financial Sector
Financial organizations like a StockBroking company can provide a mobile app which acts as a wallet to the clients so that they can carry out transactions securely and quickly.
- Healthcare Sector
Healthcare companies can use blockchain in mobile/web apps to share health records, perform medical trials and process health insurance claims.
- Real Estate Sector
Real estate or mortgage companies can integrate blockchain into their mobile/web apps to streamline selling and buying of properties and to make sure that all documents are verifiable and accurate with smart contracts.
Hyperledger Fabric is the most widely used blockchain framework by medium-sized and large enterprises. This article will explain how to develop blockchain applications for Mobile/Web Client with Hyperledger Fabric, along with a brief overview of Hyperledger Fabric.
- What is Hyperledger Fabric?
- Hyperledger Fabric components
- A step-by-step guide to develop blockchain applications on Hyperledger Fabric for Mobile/Web Client
- The flow of an application that represents how to build a blockchain app
We chose the Hyperledger Fabric platform for the demo to offer anonymity and security on users’ transactions and data. Since modern development demands resiliency, good management and scalability, it is significant to use Kubernetes for the app’s backend.
What is Hyperledger Fabric?
Hyperledger Fabric, hosted by the Linux Foundation, is an open-source, private and permissioned blockchain solution. The blockchain network is private, meaning it is not accessible to the public, and only invited parties are allowed to join it. Permission refers to the identification of each party and tracking of each transaction. Fabric networks can be run on-premises, or you can use blockchain to maintain your registry infrastructure.
Once a network has been created between several parties, they can exchange sensitive information with each other. It is useless if a Hyperledger Fabric blockchain solution does not interact with multiple parties. Fabric’s purpose is to create trust between organizations and parties.
Fabric architecture prioritizes key features like:
- Assets – Enable the exchange of money over the network.
- Chaincode – It is a concept of smart contract in Fabric
- Ledger Features – Encodes all transaction history for each channel and has SQL-like query capabilities.
- Privacy – Fabric must identify each computer in the network. Potential members of a Fabric-enabled network must sign up to identify themselves via a Membership Service Provider (MSP). This is known as “permissioned” membership. Fabric is an attractive option because it protects data privacy in many industries. Fabric does not require authorization to use any part of the blockchain. The network designer will make this decision.
- Channels – This framework allows network participants to create distinct sets of transactions hidden from larger networks. This allows more sensitive data to be isolated from sites that don’t require access.
- Scalability – Fabric’s highly scalable networking is another attractive feature. Large companies can use Fabric. It can be scaled quickly to increase the number of participants in the network, just like any other implementation. The system can, however, process large data sets with fewer resources. So, blockchains can be created with just a few nodes and scaled up as required.
- Modularity – Fabric architecture allows for individual components to be added or implemented at different times. Many components can be removed entirely or added later without compromising functionality. This feature helps companies identify what they require and what they don’t. Modular components are “plug and play” and can be used to build consensus, identity management, proper ledger storage, and integration with connecting code.
Hyperledger Fabric components
There are mainly four components in Hyperledger Fabric app layer-
- Certified authority or CA
Let us briefly introduce each of them.
- Peer – A peer in Hyperledger Fabric app layer stores all transactions made on a channel. Peers can join as many channels as they wish. However, the storage of different channels for the same peer would be separated. An organization can therefore ensure that confidential information is only shared with authorized participants.
- Orderer – It is one of the most critical components of the Fabric consensus mechanism. Orderer is responsible for creating new blocks of ordered transactions and disseminating the newly created block to all other peers via a relevant channel.
- Certified authority (CA) – It is responsible for managing user certificate management, such as user enrollment, user cancellation, etc. Moreover, Hyperledger Fabric is a permissioned blockchain network. Hyperledger Fabric uses an X.509 standard certificate that represents permissions and roles as well as attributes for each user. Users can query or invoke any transaction via any channel compatible with permissions and roles.
- Client – It is an application that interacts with the Fabric blockchain network. This means that client can interact with the Fabric network according to its permissions, roles and attributes, as defined on the certificate it received from its CA server.
A step-by-step guide to develop blockchain applications on Hyperledger Fabric for Mobile/Web Client
- Installing pre-requisites
- Technology Components involved in the development of Blockchain Applications for Web/Mobile Client
- Configuring the blockchain network
- Deploying the Blockchain Network in Kubernetes
- Exposing the backend with Kubernetes Ingress
- Configuring and testing the app
Before we proceed to the development of blockchain applications for Mobile/Web Client, it is essential to ensure that we have all pre-requisites installed on the system.
- First of all, create a Kubernetes cluster with Google Cloud Kubernetes Engine to deploy the containerized app in the cloud. Kubernetes engine eliminates the need to manage, install and operate your own clusters.
- Install Docker Engine and Docker Compose
- Install Hyperledger Fabric Node SDK to support Node.js. It enables APIs to interact with the Hyperledger Fabric Blockchain.
- Hyperledger Fabric blockchain publishes the following npm packages:
- Fabric-client- It is the main client for Hyperledger Fabric Blockchain. Applications use the client package to instantiate and install chaincodes, make queries and process transactions within the Hyperledger Fabric Blockchain Network.
- Fabric-ca-client- It is an optional client component in Hyperledger Fabric. The component enables applications to register peers and app users to create trusted identities on the blockchain network.
- Install IDE (Integrated Development Environment), which offers robust app development tools.
Technology Components involved in the development of Blockchain Applications for Web/Mobile Client
- Hyperledger Fabric v1.0 – Hyperledger Fabric is a blockchain framework implementation that is considered a foundation for developing blockchain applications or solutions for enterprises.
- Android SDK – Android SDK (Software Development Kit) is a comprehensive set of development tools to build an application for Android devices. It offers you the complete API libraries and developer tools to code, test and debug Android apps.
- iOS SDK- iOS SDK is a software development kit for developers using which they can build native apps for Apple’s iOS platforms and devices.
- Mongo DB- With its significant querying, aggregation, wide driver and indexing support, Mongo DB acts as the go-to-JSON data store for both enterprises and startups.
- Redis is an open-source, in-memory data structure store that can also be used as a message broker, database and cache. It is a good platform to use a message queue.
- Rabbit MQ- Being lightweight, RabbitMQ can be deployed easily in the cloud and on-premises. It can support multiple messaging protocols and enable you to keep a separation between app layers and data.
Once all the components and software are installed, it is time to configure a blockchain network that acts as a mobile app’s backend.
Configuring the blockchain network
Before configuring the blockchain network, it is required to get Compose for Redis and RabbitMQ credentials from the main page of each service in the Google Cloud Dashboard.
In the cofig.js file saved in the blockchain container folder, you have to modify the values for Redis and rabbitmq with your credentials.
Once the values are modified, the next step is to configure all YAML files to use the instance of MongoDB. Get the URL and certificate for the MongoDB dashboard in Compose.
Deploying the Blockchain Network in Kubernetes
Deploy all the microservices for the application in Kubernetes. Test the blockchain network with its API client and use the external IP of the service to perform a curl request.
Once the curl request is executed, check the result with the resultID you get as a result. The status “success” implies that the blockchain network can now be integrated with the app.
Before blockchain integration with the mobile app, it is required to deploy more microservices needed for the mobile app.
Exposing the backend with Kubernetes Ingress
Once the blockchain network is deployed, the backend must be exposed so the application can communicate with the network. Kubernetes Ingress offers the functionality to expose the microservices.
Configuring and testing the app
The application is configured to perform REST calls to the backend of Kubernetes. After configuring the app, it is time to test either on an emulator or a real device.
- Firstly, the internal testing is done by a group other than the developers who built it within the same organization. The software version released in the initial phase will be called as “Alpha version.”
- After alpha testing, the application undergoes beta testing, where the end-user tests it for usability, compatibility, functionality and reliability. Inputs given by the end-users can help to enhance the product’s quality and make the application successful.
- Once the end-user approves the app, it is either released as a closed beta version or a public beta. In a closed beta version, only a restricted group of individuals are invited for the testing of an application. But in a public beta release, anyone can use the application.
Let’s look at the flow of an application and explore how it works at the backend.
Here is the flow that represents how to build a blockchain app
1. When a user accesses the app and requests it to fetch the data, the request is sent to REST API, which is responsible for enabling communication between the server and web-based/mobile-based client.
The API acknowledges the request, and the mobile/web application gets a unique key to receive the blockchain’s request later.
2. API uses RabbitMQ to store the request in a queue. The queue has channels equivalent to the number of peers involved in the application. For example, if it is a peer-to-peer lending application, there will be two peers (lender and borrower), and the queue will have two channels.
In the case of peer-to-peer lending, the request can either be:
- Enroll a lender/borrower.
- Request a loan.
- Query data from the blockchain.
- Invoke or perform a transaction.
3. The execution workers (node) use Hyperledger Fabric Blockchain’s SDK to process the requests by listening to them from RabbitMQ.
4. Hyperledger Fabric uses the Ordering Service to accept endorsed transactions, put blocks into a specific order and deliver blocks to the committing peers in the network.
4. The blockchain network uses NFS (Network File System) to hold the state database and ledger.
5. Before any request is processed, the fabric-ca client authenticates a peer’s identification and approves the transaction request.
6. The execution workers get the response to the request and hold it in the Redis Database (Cache) with the unique key.
7. The web/mobile app queries the Redis database with the unique key.
8. The data generated from the microservices are held in MongoDB so that information can be fetched quickly whenever someone queries the blockchain network.
At LeewayHertz, we have in-depth knowledge of developing blockchain applications using various blockchain platforms like Hyperledger Fabric/Sawtooth, EOS, Hedera Hashgraph and Ethereum. If you are looking for a blockchain technology company to develop blockchain application, consult our blockchain developers and discuss your business needs.
The Hyperledger Fabric framework and blockchain technology have the potential to transform many sectors around the world. Hyperledger’s strategic goal to develop business solutions using blockchain technology differs from currency-based blockchains. Hyperledger Fabric is a unique, flexible, and extensible architecture that differentiates it from other blockchain solutions. Building the future enterprise blockchain will require building on top of a fully-vetted open-source architecture, and Hyperledger Fabric is your starting point.
At LeewayHertz, we have in-depth knowledge of developing a blockchain-based application using various blockchain platforms like Hyperledger Fabric/Sawtooth, EOS, Hedera Hashgraph and Ethereum. If you are looking for a blockchain technology company to build your project, consult our blockchain developers and discuss your business needs.
Start a conversation by filling the form
All information will be kept confidential.