Deploying Proof of Stake Blockchain Applications on IBM Cloud Using Tendermint
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.
Properties of Tendermint
- Byzantine Fault-Tolerant: Tendermint tolerates up to one third of your machines failing arbitrarily. This includes explicitly malicious behaviour.
- State Machine Replication: Tendermint can replicate deterministic state machines written in any programming language.
- Secure P2P: Gossip protocols and peer discovery are secured via Tendermint’s authenticated encryption system.
- 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
- Signup to IBM Cloud for free
- Install Cloud Foundry CLI
- Install IBM Cloud CLI
- Install Docker
- Install Kubernetes
- Clone the repo
$ git clone https://github.com/SaifRehman/tendermint-chat-app
7. ⭐ the repo :)
8. Creating the Genesis file and populating it with 2 validators
- Navigate to creatingGenesisFile directory
$ cd creatingGenesisFile
- Install Dependencies
$ npm i
- You will find genesis.json directory and it will look like following below without any validators
- Generate 2 validators
$ ./node_modules/lotion/bin/tendermint gen_validator > privkey0.json$ ./node_modules/lotion/bin/tendermint gen_validator > privkey1.json
- Clean your private key: Eliminate unnecessary info like ( last_height , last_round, last_step, last_signature )
- Note: Each time you will get a different combination
- Populating genesis.json with the following keys generated, only add your public key not private :)
Cool now we understood how to set our genesis file :)
10. Create your cluster on IBM Cloud
- Go to Go to your IBM Cloud Dashboard and Sign in
- Go to IBM Container Service
- 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.
$ bx plugin install container-service -r Bluemix
- Log in to your IBM Cloud account.
$ bx login -a https://api.eu-de.bluemix.net <depends which region you deployed your cluster>
$ bx cs region-set eu-central <depends which region you deployed your cluster>
- Get the command to set the environment variable and download the Kubernetes configuration files.
$ bx cs cluster-config nameOfYourCluster
- 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.
$ export KUBECONFIG=/Users/ibm/.bluemix/plugins/container-service/clusters/Saif1Cluster/kube-config-mil01-nameOfYourCluster.yml
- Verify that you can connect to your cluster by listing your worker nodes.
$ kubectl get nodes
11. Build your docker image of your validator1
- Update node0 peer ip accordingly, your peer ip will be another peer on another cluster
- Navigate to node1 directory
$ cd node1
- Build your Docker image
$ docker build -t node1 .
- Go to your IBM Cloud Registery
- Choose a name for your first namespace, and create that namespace.
$ bx cr namespace-add <my_namespace>
- Log your local Docker daemon into the IBM Cloud Container Registry.
$ bx cr login
- 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.
$ docker tag node1 registry.<region-short-term>.bluemix.net/<my_namespace>/node1:latest
- Push the image.
$ docker push registry.<region-short-term>.bluemix.net/<my_namespace>/node1:latest
- Verify that your image is in your private registry.
$ bx cr image-list
- 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
- Create and Deploy the service :)
$ kubectl create -f service-deployment.yml
- Delete all deployments
$ kubectl delete deployments --all
- Delete all services
$ kubectl delete services --all
- Follow the same procedure with node 2 and deploy
- Access pods and logs
$ kubectl get pods
$ kubectl logs podname
- 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
12. Cook a sexy UI with ionic to interact with those 2 validators and send txs
- Install Ionic
$ npm i -g ionic cordova
- Open
manifest.yml
and give app a name fromcf/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
$ ionic cordova platform rm browser
$ ionic cordova platform add browser
$ ionic cordova build browser
- 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:
$ cf api https://api.ng.bluemix.net
$ cf login -u bluemix_id
If you are using United Kingdom region:
use these commands:
$ cf api https://api.eu-gb.bluemix.net
$ cf login -u bluemix_id
for Sydney region
$ cf api https://api.au-syd.bluemix.net
$ cf login -u bluemix_id
for Germany region
$ cf api https://api.eu-de.bluemix.net
$ cf login -u bluemix_id
After logging in push your app :)
$ cd cf
$ cf push
Note that your frontend app is not a validator node, its just a node that connects to 2 validator nodes on cloud
- You can access tendermint rpc api from here
http://workernodeip:30090
13. Endpoints to interact with your blockchain by Cloud Foundry Tendermint apis
Please star the repo if you liked it :)
Resources
Tendermint Chat App Repo
Lotionjs Repo
Tendermint Repo
Tendermint Documentation
Read more:
- 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!