Building dApp on Cosmos SDK, Tendermint

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@sansteem·
0.000 HBD
Building dApp on Cosmos SDK, Tendermint
# Many Chains, Many Coins, One Ecosystem

![image.png](https://steemitimages.com/DQmZShsCfxKX4zy5piF21GrKk3Q2B7suCfvDSMmhr4Egmvq/image.png)

* __Cosmos__ - Internet of Blockchains
* __CosmosHub__ - Internet Service Provider (ISP)
* __Tendermint__ - Blockchain Consensus 
* __ABCI__ - TCP/IP

## Simplified Architecture of blockchain including Bitcoin
![image.png](https://steemitimages.com/DQmUhaNbuv9a9BDiFMDXwS1Ked5gbdwvnJXPto5aRVmE3bt/image.png)

* The __network protocol__ is how nodes in the network tell each other about new transactions, blocks, and other nodes; usually a p2p gossip network.
* The __consensus protocol__ is the set of rules that nodes should follow to determine which particular ordered set of transformations should be in the ledger at a given moment. In Bitcoin, the chain with the highest difficulty seen by a node is treated as authoritatively correct.
* The __transaction protocol__ describes what makes transactions valid, and how they should mutate the blockchain's state.

## Extended Architecture - __Ethereum__
![image.png](https://steemitimages.com/DQmSiNsMyndfMXojVSpbizRDKVv3KNNe4PvGqTdFqXvjQxC/image.png)
* Focus only on Application (EVM) as a state machine
* Not able to change any deeper level of stacks
* Poor performance - scalability issue

## Can Tendermint Core resolve those issues?
![image.png](https://steemitimages.com/DQmeZ2YFyXBgLrgCvAixiuV7SW8tQyy7tYKD1LLFGPxs8b1/image.png) 

* Proof of Stake (__PoS__) BFT Consensus algorithm is faster (1-3 sec) than Bitcoin’s synchronous consensus (>10 mins)
* Interoperable for both Public & Private Chains
* Instant Finality
* Highly Scalable
* Guarantees safety in asynchronous & liveness in weakly synchronous environments
* Basis for other PoW systems like Casper

## Cosmos Ecosystem
![image.png](https://steemitimages.com/DQmdS1ajKSmzKr4nUZihh6pmgJBjiEnB2qAP68zkat4koiV/image.png)

## OK, now what?
_Let’s build something on this cool ecosystem._

### Lotion
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. Lotion lets you write secure, scalable applications that can easily interoperate with other blockchains on the Cosmos Network using IBC.

Github `https://github.com/keppel/lotion`

When you're writing a Lotion app, you're only responsible for writing the transaction protocol. Under the hood, Tendermint is handling the consensus and network protocols. When you start your lotion app, a Tendermint node is also started which will handle all of the communication with other nodes running your lotion app.

1. `$ npm install lotion`
2. Create a javascript file called `my-lotion-app.js` and run it by
3. $ node my-lotion-app.js

code for `my-lotion-app.js`

```
let app = require('lotion')({
  initialState: { count: 0 }
})

app.use((state, tx) => {
  state.count++
})

app.listen(3000)
```

## How to test it? By using `curl`

`$ curl http://localhost:3000/state`
> {"count":0}

`$ curl http://localhost:3000/txs -d '{}'`
> {"result":{"check_tx":{"code":0,"data":"","log":"","gas":"0","fee":"0"},"deliver_tx":{"code":0,"data":"","log":"","tags":[]},"hash":"60A4191756CDAE902D6DF6341F0E31458DB856BB","height":105}} 

`$ curl http://localhost:3000/state`
> {"count":1}

You can make a working blockchain app with javascript and really easy!


## For more information about Cosmos:
https://www.youtube.com/watch?v=LApEkXJR_0M
👍 , , ,