Building dApp on Cosmos SDK, Tendermint
Many Chains, Many Coins, One Ecosystem
- Cosmos - Internet of Blockchains
- CosmosHub - Internet Service Provider (ISP)
- Tendermint - Blockchain Consensus
- ABCI - TCP/IP
Simplified Architecture of blockchain including Bitcoin
- 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
- 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?
- 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
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.
$ npm install lotion
- Create a javascript file called
my-lotion-app.js
and run it by - $ 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!
Great post! I'm just wondering, may I use the image from the top of the page for a video presentation?