Tendermint tutorial
mkdir -p ~/work/tendermint
cd ~/work/tendermint
git clone https://github.com/tendermint/tendermint.git
Build Tendermint and install executable in $GOPATH/bin/tendermint
cd tendermint
go mod tidy
make tools
make install
Create default node config in a sample folder. Note that if TMHOME
is not specified, the config will be created in $HOME/.tendermint
.
mkdir -p ~/work/tendermint/node
cd ~/work/tendermint/node
TMHOME="." tendermint init
Assume that this repo is cloned in ~/work/tendermint/kvstore
.
cd ~/work/tendermint/kvstore
# go mod init github.com/yxuco/tendermint-kvstore
go mod tidy
go build
start the kvstore app, which will wait for tendermint node to connect.
cd ~/work/tendermint/node
rm example.sock
../kvstore/kvstore
In another terminal, start a full tendermint node, and connect it to kvstore app.
cd ~/work/tendermint/node
TMHOME="." tendermint node --proxy_app=unix://example.sock
From another terminal, send a transaction
curl -s 'localhost:26657/broadcast_tx_commit?tx="tendermint=rocks"'
Send a query
curl -s 'localhost:26657/abci_query?data="tendermint"'
echo -n "dGVuZGVybWludA==" | base64 --decode
echo -n "cm9ja3M=" | base64 --decode
Shutdown Tendermint node and kvstore app from the previous testing. Restart the kvstore
app as a built-in
app.
../kvstore/kvstore -config "./config/config.toml" -built-in true
The built-in app itself is a full Tendermint node. From another terminal, send new transaction and query similar the previous tests.
When sending transaction and queries using JSON-RPC, instead of OpenAPI in the previous steps, you need to encode the data carefully as required by the app.
Transaction parameters must use base64 encoding, e.g.,
tx=$(echo -n "tendermint=jsonrpc" | base64)
curl --header "Content-Type: application/json" --request POST --data '{"method": "broadcast_tx_commit", "params": {"tx": "'${tx}'"}, "id": 1}' localhost:26657
Query parameters must use HEX dump, e.g.,
data=$(echo -n "tendermint" | xxd -pu)
curl --header "Content-Type: application/json" --request POST --data '{"method": "abci_query", "params": {"data": "'${data}'"}, "id": 2}' localhost:26657
Install wscat
npm install -g wscat
Start wscat
and connect to a full tendermint node, then subscribe NewBlock
events
wscat --connect ws://localhost:26657/websocket
{ "jsonrpc": "2.0", "method": "subscribe", "params": ["tm.event='NewBlock'"], "id": 1 }