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.
In this article, we will explain how to develop a blockchain application for Mobile/Web Client with Hyperledger Fabric.
We chose Hyperledger Fabric platform for the demo to offer anonymity and security on users’ transactions and data. Since modern development demands for resiliency, good management and scalability, it is significant to use Kubernetes to develop blockchain application backend.
Here’s a step-by-step guide on how to develop blockchain applications on Hyperledger Fabric
As it is clear how blockchain can benefit your business, we have explained how to develop blockchain applications on Hyperledger Fabric. However, we can build blockchain apps on various blockchain platforms, including Corda, Stellar, Ethereum, EOS and many more.
Before we explain how to develop blockchain application for Mobile/Web Client, it is essential to ensure that we have all prerequisites 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. Hyperledger Fabric 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 tools to develop apps.
Technology Components involved in the development of Blockchain Applications for Web/Mobile Client
- Hyperledger Fabric v1.0
Hyperledger Fabric is a blockchain framework implementation which is considered as a foundation to develop blockchain application 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.
- React Native
- Mongo DB
- Hyperledger Fabric v1.0
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 which 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 the time to configure a blockchain network which acts as a backend for the mobile app.
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 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 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 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 back-end has to be exposed so that 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 the time to test either on an emulator or a real device.
- Firstly, internal testing is done by a group of people other than the blockchain application developers who built it, but 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 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 understands 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 server and web-based/mobile based client. The API acknowledges the request and the mobile/web application gets a unique key which is used 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 blockchain 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 loan, query data from the blockchain, or 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.
5. The blockchain network uses NFS (Network File System) to hold the state database and ledger.
6. Before any request is processed, fabric-ca client authenticates the identification of a peer and approves the request for the transaction.
7. The execution workers get the response to the request and hold it in the Redis Database (Cache) with the unique key.
8. The web/mobile app then queries the Redis database with a unique key.
9. 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.
Start a conversation by filling the form
Once you let us know your requirement, our technical expert will schedule a call and discuss your idea in detail post sign of an NDA.
All information will be kept confidential.