Ubuntu18.04简单使用tendermint

① 启动tendermint并检查状态
  • 初始化tendermint
$ tendermint init
  • 单节点方式启动tendermint,并使用内置应用kvstore-proxy_app运行标志用来指定一个内置的ABCI应用,例如kvstore是tendermint程序内置的键值对应用。
$ tendermint node --proxy_app=kvstore
# 如果之前已经使用过tendermint,只需要初始化data就可以
$ tendermint unsafe_reset_all
  • 查看状态
$ curl -s localhost:26657/status
{
     
  "jsonrpc": "2.0",
  "id": "",
  "result": {
     
    "node_info": {
     
      "protocol_version": {
     
        "p2p": "7",
        "block": "10",
        "app": "1"
      },
      "id": "d774d477fd4f339058d7dc35edf75f32371fc5b7",
      "listen_addr": "tcp://0.0.0.0:26656",
      "network": "test-chain-F5dt3c",
      "version": "0.31.5",
      "channels": "4020212223303800",
      "moniker": "master",
      "other": {
     
        "tx_index": "on",
        "rpc_address": "tcp://0.0.0.0:26657"
      }
    },
    "sync_info": {
     
      "latest_block_hash": "B6B423295B7641BD540DF051F2597984784B5F93C27FE3ED053B9B75447368EC",
      "latest_app_hash": "0000000000000000",
      "latest_block_height": "252",
      "latest_block_time": "2019-05-01T11:35:34.80586108Z",
      "catching_up": false
    },
    "validator_info": {
     
      "address": "4252DFF3DD179BB27E73EBCBE0B9B706F7E7CBF9",
      "pub_key": {
     
        "type": "tendermint/PubKeyEd25519",
        "value": "OpVAF6IXhA7r5nF+DqgNLTvfE1TQXOuKT93yFawTA/Y="
      },
      "voting_power": "10"
    }
  }
}
② 提交交易
  • 提交一个交易,使用curl向Tendermint节点的RPC服务发出请求。没有指定key,value,lucy既是key,又是value
$ curl -s 'localhost:26657/broadcast_tx_commit?tx="lucy"'
{
     
  "jsonrpc": "2.0",
  "id": "",
  "result": {
     
    "check_tx": {
     
      "gasWanted": "1"
    },
    "deliver_tx": {
     
      "tags": [
        {
     
          "key": "YXBwLmNyZWF0b3I=",
          "value": "Q29zbW9zaGkgTmV0b3dva28="
        },
        {
     
          "key": "YXBwLmtleQ==",
          "value": "bHVjeQ=="
        }
      ]
    },
    "hash": "DC99E9AA86FAB83A062CFF5E0808391757071A3D5DBB942802D5F923AAEAD3B4",
    "height": "299"
  }
}
  • 返回的 Response 中的 key 和 value 使用了 base64 进行了编码,例如,结果中的value字段,例如bHVjeQ==,这其实是字符串lucybase64编码。我们可以通过命令 base64 对其进行解码,结论:可以发现key = lucy
$ echo "YXBwLmNyZWF0b3I=" | base64 -d
app.creator
$ echo "Q29zbW9zaGkgTmV0b3dva28=" | base64 -d
Cosmoshi Netowoko
$ echo "YXBwLmtleQ==" | base64 -d
app.key
$ echo "bHVjeQ==" | base64 -d
lucy
  • 也可以指定key和value,提交一个交易:
$ curl -s 'localhost:26657/broadcast_tx_commit?tx="name=tiger"'
{
     
  "jsonrpc": "2.0",
  "id": "",
  "result": {
     
    "check_tx": {
     
      "gasWanted": "1"
    },
    "deliver_tx": {
     
      "tags": [
        {
     
          "key": "YXBwLmNyZWF0b3I=",
          "value": "Q29zbW9zaGkgTmV0b3dva28="
        },
        {
     
          "key": "YXBwLmtleQ==",
          "value": "bmFtZQ=="
        }
      ]
    },
    "hash": "EC6087612FF50A1BF5353EF0F7F344F33EDCCFD511939EE063DD4840E599795D",
    "height": "620"
  }
}
$ echo "bmFtZQ==" | base64 -d'
name
③ 查询交易
  • 查询第一个交易,该交易没有指定key,key和value均为lucy:
$ curl -s 'localhost:26657/abci_query?data="lucy"'
{
     
  "jsonrpc": "2.0",
  "id": "",
  "result": {
     
    "response": {
     
      "log": "exists",
      "key": "bHVjeQ==",
      "value": "bHVjeQ=="
    }
  }
}
$ echo "bHVjeQ==" | base64 -d
lucy
  • 查询第二个交易,key为name,value为tiger
$ curl -s 'localhost:26657/abci_query?data="name"'
{
     
  "jsonrpc": "2.0",
  "id": "",
  "result": {
     
    "response": {
     
      "log": "exists",
      "key": "bmFtZQ==",
      "value": "dGlnZXI="
    }
  }
}
$ echo "bmFtZQ==" | base64 -d
name
$ echo "dGlnZXI=" | base64 -d'
tiger

参考链接:
自主可控区块链神器Tendermint五分钟入门
区块链框架 Tendermint 入门教程

你可能感兴趣的:(区块链)