Taxonomy Icon

Mobile Development

Create an Android app with Blockchain integration

Get the code

Description

People who aware of their health and fitness often use mobile applications to track their data. Some of those apps reward them for reaching certain goals or tasks. With more people becoming more conscious about what data they give to the application developers, we use Hyperledger Fabric (a blockchain framework implementation) to provide anonymity and security on people’s data and transactions. The Android app tracks the users’ steps and rewards them with “Kubecoins” which they can exchange for swag.

Overview

Modern development requires scalability, resiliency, and good management, and that’s why we chose to use Kubernetes for our Android app’s backend. We chose to use Hyperledger Fabric to enable the app with Blockchain capabilities. We used MongoDB for our data storage and RabbitMQ and Redis to optimize Blockchain requests.

This code pattern is for developers who want to provide data anonymity and security to their users. Their users will be more confident to use their app if it gives them more control over their privacy. The developers can also extend the pattern to use the backend from different platforms.

The Android application was used in KubeCon Europe 2018.

When you have completed this code pattern, you will understand how to:

  • Build a native Android app and use Google Fit for its steps data
  • Deploy a Blockchain network in Kubernetes
  • Integrate the Android app with the Blockchain network

Flow

flow

  1. The REST API is how the mobile app will interact with the blockchain network. The API will acknowledge the request, and the mobile app will receive a unique key (random numbers and letters) which will be used to get the blockchain’s response later.
  2. The API just stores the request in a queue in RabbitMQ. The queue has 2 channels, which are for the user (Fitcoin org) and the seller (Shop org). The requests can either be: enroll a user, query data from the blockchain network, or invoke or perform a transaction.
  3. The execution workers use the Hyperledger Fabric Node.js SDK to perform the requests. They are listening to the requests from RabbitMQ.
  4. The execution workers send the requests to the Blockchain network, which are then processed. The blockchain network uses NFS to persist the ledger and state database.
  5. The execution workers receive the response and then persists it in the Redis database with the unique key from #1.
  6. The mobile app will continue to wait for the blockchain’s response results that should be in the Redis database. The mobile app will query the Redis database with the unique key.
  7. The Registration microservice is used to create a user or update the user’s steps. When the blockchain network enrolls a user, this service uses the user ID assigned by the blockchain network.
  8. When a user is registered, it calls an IBM Cloud Function to generate a random name and avatar for the user.
  9. The data from the microservices (the user’s data (steps, name, and avatar) and mobile assets (booklet/articles in the first view of mobile app)) are persisted in MongoDB.
  10. The mobile assets microservice is used to query the MongoDB to get dynamic data for the mobile app. The booklet in the first view uses the database for its content.
  11. The leaderboard microservice is used to get the standings of the users.

Instructions

Find the detailed steps for this pattern in the README. The steps show you how to:

  1. Clone the repo for the pattern
  2. Create IBM Cloud services
  3. Configure the Blockchain Network
  4. Deploy the Blockchain Network in Kubernetes
  5. Deploy and configure the microservices in Kubernetes
  6. Expose the back-end with Kubernetes Ingress
  7. Configure the Android app
  8. Test the Android app