Decided to write some articles on Block Chain Development (BloChaDev - like maybe Russians and Japanese will call it ;) ). I'm interested in this topic from a long time, but most of the articles just showing you how to add a simple hash sum to the next block and that's it. Nothing from the real world of connected nodes - consensus protocols, state management etc. Disappointing, a?
Developing chain applications is pretty hard work, so starting from scratch is not very pleasant. Some frameworks I tried, like Truffle , OpenZeppelin etc. was step in the right direction, but still not very easy - new programming language, a lot of restrictions (integers only, no random etc.).
Founding a real world working OSS project is a very, very good way to start. I researched for a while and this bring me to Cosmos , and most specifically to Cosmos SDK - "...A Framework for Building High Value Public Blockchains...". Great, let's start digging...
Reading the project documentation however I found something even better - Tendermint Core . An amazing project! Working horse for a lot of blockchain related OSS development projects. Let's start from the core!
Tendermint Core
Main Programming Language: Go
Other languages implementations: LotionJS (TypeScript)
Docker images: YES
Project describes itself as "...Byzantine fault-tolerant replicated state machines in any programming language...". Pretty cryptic... What they really saying is, that the project provide the whole underlying blockchain structure - you basically get all complex operations, like consensus, state replications etc. for free .
Then the programmer just need to implement the real state machine application and connect it to this blockchain via ABCI - "...ABCI is the interface between Tendermint (a state-machine replication engine) and your application (the actual state machine)...".
It can be done in different ways, but the simplest one, that I like most, is via unix socket, so you keep you application state completely separate from the blockchain.
OK, less talking and more doing. Let's use Tendermint for real.
Installation (or even without it)
I like projects, providing docker images! So easy to start and also keeping my development machine clean. If for some reason you cannot install Golang or if Tendermint compilation is impossible, start with the provided docker images:
docker run -it --rm -v "/tmp:/tendermint" tendermint/tendermint init
docker run -it --rm -v "/tmp:/tendermint" tendermint/tendermint node
And voilà! , you have your blockchain ready!
If you want to install the Go package (and you already have working Go development environment):
mkdir -p $GOPATH/src/github.com/tendermint
cd $GOPATH/src/github.com/tendermint
git clone https://github.com/tendermint/tendermint.git
cd tendermint
make tools
make install
make install_abci
Last line is not in the manual, but believe me, you will need this little gem, abci-cli
Getting started (GENESIS, chapter 1)
Like with every real blockchain first step is to generate your genesis :
tendermint init
On OS X and Linux it will create a special directory - ~/.tendermint/ with all needed configuration files. If you want for some reasons to start over and recreate your blockchain:
tendermint unsafe_reset_all
Preinstalled applications
After the compilation, you will have some already preinstalled applications to play with. They can be started as:
tendermint node --proxy_app=kvstore
tendermint node --proxy_app=counter
Little perl in the crown
The main reason form me to not use docker images and install Tendermind natively was the ABCI command line tool - abci-cli . Think about it as a shell around the blockchain, allowing you to start preinstalled applications, send commands, debug etc. For example to start sending requests to the preinstalled kvstore
application you can start it as:
console1$ abci-cli kvstore
...Starting ABCIServer service
console2$ tendermint node
...Starting Node service
console3$ abci-cli console
> info
-> code: OK
...
> deliver_tx "def=xyz"
-> code: OK
Booooom, real shell, connected to the blockchain. And to make it even more awesome, you can wrap it with the readline
tool (hint: brew install rlwrap
on OS X). This will give you persistent history, completion etc.:
console$ rlwrap abci-cli console
Playing with the preinstalled applications become boring very soon, so maybe it is time to make your own awesome blockchain application.
Create your own application in Go
If you understand enough Go, you can follow the manual . In the end of this manual, you will have a ready application, that you can connect to the blockchain:
export GO111MODULE=on
go mod init github.com/me/example
...some Golang coding...
go build
rm -rf /tmp/example
TMHOME="/tmp/example" tendermint init
rm example.sock
./example
TMHOME="/tmp/example" tendermint node --proxy_app=unix://example.sock
Create applications in other languages
If your app is not written in Go, run it in another process, and use the --proxy_app
flag to specify the path to the socket to connect to, for instance:
tendermint node --proxy_app=/var/run/your_app.sock
Tendermint is more protocol, then application. And Golang is just one of its implementations. If you do not know Golang or don't like it, no problems, program in your preferred language. ABCI is the way. You can replace even the underlying blockchain itself. For example if you are JavaScript developer, implementing blockchain wallet, everything can be done in JavaScript:
npm install lotion
npm install -g lotion-cli
...some JS coding..
node app.js
lotion send <GCI> '{ "nonce" : 0 }'
Summary
Tendermint Core is a great foundation for every blockchain developer. It is joy to play with and not only play, but develop serious applications too. As a side note, personally for me, Tendermint is still pretty low level, so programming real state machine applications is difficult . Will try some higher level SDK next time - for example Cosmos SDK. Stay tuned...
Additional Information
How to write Tendermint Applications using Python, or in any other language
Tendermint CAS demo - Golang application
Coming soon: Cosmos, AVA, Polkadot
P.S. I know I will not become rich, writing these articles, but contributing a small amount of BCH will be hugely appreciated, will support my work and keep me going.