Tendermint Overview and KV Store Example: Installation, Execution, and Code Walkthrough
This article introduces Tendermint’s modular blockchain framework, explains its Core and ABCI components, provides step‑by‑step installation and execution of the built‑in key‑value store example, demonstrates transaction creation and querying, and walks through the Go source code for CheckTx, DeliverTx, and Commit functions.
Tendermint is a modular blockchain application framework that provides Byzantine Fault Tolerance (BFT) consensus. It consists of two main parts: Tendermint Core, which implements the p2p network, block propagation, and the BFT consensus algorithm, and the ABCI (Application Blockchain Interface) layer, where application logic such as transaction validation and query handling can be written in various languages (e.g., Go, JavaScript).
The Core and ABCI run as separate processes and communicate through three connections: one for transaction validation (which forwards accepted transactions to the mempool), one for block proposals, and one for state queries.
Running the built‑in KV store example
First, install Tendermint and the ABCI CLI:
go get -u github.com/tendermint/tendermint/cmd/tendermint
go get -u github.com/tendermint/abci
cd $GOPATH/src/github.com/tendermint/abci
make installVerify the installation:
which tendermint
/Users/hbliu/go/bin/tendermint
which abci-cli
/Users/hbliu/go/bin/abci-cliInitialize the node configuration and start the KV store application:
tendermint init
abci-cli kvstoreStart the Tendermint node (the flag disables empty block production):
tendermint node --consensus.create_empty_blocks=falseTo store a key‑value pair (key name , value hbliu ) use the broadcast endpoint:
curl -s 'localhost:46657/broadcast_tx_commit?tx="name=hbliu"'The response contains base64‑encoded keys and values, which can be decoded with the base64 command:
echo "YXBwLmtleQ==" | base64 -D # app.key
echo "bmFtZQ==" | base64 -D # nameQuery the stored value:
curl -s 'localhost:46657/abci_query?data="name"'The returned JSON again uses base64; decoding yields the original key and value ( name → hbliu ). The web UI at http://localhost:46657 lists all available APIs.
Key source code (Go)
func (app *KVStoreApplication) CheckTx(tx []byte) types.ResponseCheckTx {
return types.ResponseCheckTx{Code: code.CodeTypeOK}
}CheckTx simply approves every transaction, placing it into the mempool.
func (app *KVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
var key, value []byte
parts := bytes.Split(tx, []byte("="))
if len(parts) == 2 {
key, value = parts[0], parts[1]
} else {
key, value = tx, tx
}
app.state.db.Set(prefixKey(key), value)
app.state.Size += 1
tags := []cmn.KVPair{{[]byte("app.creator"), []byte("jae")}, {[]byte("app.key"), key}}
return types.ResponseDeliverTx{Code: code.CodeTypeOK, Tags: tags}
}DeliverTx parses the incoming transaction, stores the key‑value pair in the application state, updates the size counter, and returns tags.
func (app *KVStoreApplication) Commit() types.ResponseCommit {
// Using a memdb – just return the big endian size of the db
appHash := make([]byte, 8)
binary.PutVarint(appHash, app.state.Size)
app.state.AppHash = appHash
app.state.Height += 1
saveState(app.state)
return types.ResponseCommit{Data: appHash}
}Commit finalizes the block by computing a simple hash from the state size, increments the block height, persists the state, and returns the new app hash.
The article concludes with a reference to the official Tendermint introduction documentation.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.