Deploying Proof of Stake Blockchain Applications on IBM Cloud Using Tendermint

Saif Rehman
Coinmonks
7 min readMar 15, 2018

--

Introduction

Blockchain is one the greatest technological innovations since the Internet. The Internet empowers free flow of information, while the Blockchain empowers frictionless flow of value. Companies from various disciplines are now adopting Blockchain for real-world business use cases. The amount of research going on in applied cryptography is unprecedented. We are right now experiencing the largest civilian deployment of public key cryptography ever, and that is the Bitcoin.

While Blockchain is very interesting technology, it is also nascent. It is challenging to do a rapid prototype of a blockchain application and run it on Cloud. Tendermint allows you to rapidly create Blockchain application as it handles the underlying blockchain layers such as networking and consensus, and allows the developer to only focus on application layer through ABCI (Application Blockchain Interface)

In this blog post, I will show you how to easily create a Blockchain chat application and deploy it to cloud using Tendermint, Lotionjs, and Ionic.

What is Tendermint?

“Tendermint is software for securely and consistently replicating an application on many machines.”

To simply put Tendermint is a software which can be used to achieve Byzantine fault tolerance (BFT) in any distributed computing platforms. From managing infrastructure to designing a distributed database, we can use Tendermint. Tendermint is built on 2 important technical components.

Consensus Engine: Also known as Tendermint core, this ensures that each transaction is recorded in every machine in the same order through Proof of Stake consensus.

ABCI (Application Blockchain Interface): Enables transaction to be processed in any programming language.

Get Best Software Deals Directly In Your Inbox

Properties of Tendermint

  1. Byzantine Fault-Tolerant: Tendermint tolerates up to one third of your machines failing arbitrarily. This includes explicitly malicious behaviour.
  2. State Machine Replication: Tendermint can replicate deterministic state machines written in any programming language.
  3. Secure P2P: Gossip protocols and peer discovery are secured via Tendermint’s authenticated encryption system.
  4. Lightning Fast: Tendermint supports thousands of transaction per second at 1000ms latencies.

What is Lotionjs

Lotion is a new way to create blockchain apps in JavaScript, which aims to make writing new blockchains fast and fun. It builds on top of Tendermint using the ABCI protocol.

Creating a Blockchain Chat Application with 2 Tendermint Validator Nodes Deployed on IBM Cloud

Prerequisites

  1. Signup to IBM Cloud for free
  2. Install Cloud Foundry CLI
  3. Install IBM Cloud CLI
  4. Install Docker
  5. Install Kubernetes
  6. Clone the repo

7. ⭐ the repo :)

8. Creating the Genesis file and populating it with 2 validators

  • Navigate to creatingGenesisFile directory
  • Install Dependencies
  • You will find genesis.json directory and it will look like following below without any validators
  • Generate 2 validators
How Private Key looks like
  • Clean your private key: Eliminate unnecessary info like ( last_height , last_round, last_step, last_signature )
This is how your cleaned privkey0.json
This is how your cleaned privkey0.json
  • Note: Each time you will get a different combination
  • Populating genesis.json with the following keys generated, only add your public key not private :)
This is how your genesis file will look like in the end with two validators

Cool now we understood how to set our genesis file :)

10. Create your cluster on IBM Cloud

  • Click on Create Cluster
  • Give a name to your cluster and deploy
  • Wait for your cluster to be ready
  • Once ready, click on your cluster, and click on worker nodes to check its public ip and note it down
  • Click on Access tab
  • Now to Access your cluster hosted on IBM Cloud do the following steps
  • Install the container service plugin.
  • Log in to your IBM Cloud account.
  • Get the command to set the environment variable and download the Kubernetes configuration files.
  • Set the KUBECONFIG environment variable. Copy the output from the previous command and paste it in your terminal. The command output should look similar to the following.
  • Verify that you can connect to your cluster by listing your worker nodes.

11. Build your docker image of your validator1

validator1
  • Update node0 peer ip accordingly, your peer ip will be another peer on another cluster
  • Navigate to node1 directory
  • Build your Docker image
Dockerfile of node1 (validator1)
Image being built :)
  • Go to your IBM Cloud Registery
  • Choose a name for your first namespace, and create that namespace.
  • Log your local Docker daemon into the IBM Cloud Container Registry.
  • Choose a repository and tag by which you can identify the image. Use the same repository and tag for the rest of this Quick Start.
  • Push the image.
once you push you will have it uploaded in ibm’s private registry :)
  • Verify that your image is in your private registry.
  • Now once you have successfully deployed, you have to deploy to IBM container using kubernetes and make tendermint port and p2p port accessible publicly
  • Create service-deployment.yml accordingly to your private registry setup
Deployment file
  • Create and Deploy the service :)
  • Delete all deployments
  • Delete all services
  • Follow the same procedure with node 2 and deploy
  • Access pods and logs
  • If both validator nodes are successfully deployed and you log one of them, you will see blocks will start committing since they are in synch with each other
Means both validators are in synch :)

12. Cook a sexy UI with ionic to interact with those 2 validators and send txs

  • Install Ionic
  • Open manifest.yml and give app a name from cf/manifest.yml
  • Open frontend/src/pages/congif/config.ts , and give app name you mentioned in manifest.yml
  • Navigate to frontend directory and build the app
  • Navigate to cf folder, and push the app, this will have a fully functional Blockchain with a sexy frontend build with ionic 💖
  • Login to IBM cloud with cf cli

If you are using US South Region:

use these commands:

If you are using United Kingdom region:

use these commands:

for Sydney region

for Germany region

After logging in push your app :)

If all works well your frontend app will be up and running

Note that your frontend app is not a validator node, its just a node that connects to 2 validator nodes on cloud

You connect it with peer port, running on 30092 as mentioned :)
  • You can access tendermint rpc api from here

13. Endpoints to interact with your blockchain by Cloud Foundry Tendermint apis

Endpoints :)

Please star the repo if you liked it :)

Resources

Tendermint Chat App Repo

Lotionjs Repo

Tendermint Repo

Tendermint Documentation

https://tendermint.com/docs

Read more:

  1. Follow me for more: https://www.engineerability.com

Conclusion

Tendermint has made it easy for business developers to write blockchain applications, and the IBM Cloud made it easy to deploy and operate such applications. I look forward to seeing your blockchain applications!

--

--