You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.3 KiB

  1. # RPC
  2. Tendermint supports the following RPC protocols:
  3. * URI over HTTP
  4. * JSONRPC over HTTP
  5. * JSONRPC over websockets
  6. Tendermint RPC is build using [our own RPC library](https://github.com/tendermint/tendermint/tree/master/rpc/lib). Documentation and tests for that library could be found at `tendermint/rpc/lib` directory.
  7. ### Configuration
  8. Set the `laddr` config parameter under `[rpc]` table in the $TMHOME/config.toml file or the `--rpc.laddr` command-line flag to the desired protocol://host:port setting. Default: `tcp://0.0.0.0:46657`.
  9. ### Arguments
  10. Arguments which expect strings or byte arrays may be passed as quoted strings, like `"abc"` or as `0x`-prefixed strings, like `0x616263`.
  11. ### URI/HTTP
  12. Example request:
  13. ```bash
  14. curl -s 'http://localhost:46657/broadcast_tx_sync?tx="abc"' | jq .
  15. ```
  16. Response:
  17. ```json
  18. {
  19. "error": "",
  20. "result": {
  21. "hash": "2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF",
  22. "log": "",
  23. "data": "",
  24. "code": 0
  25. },
  26. "id": "",
  27. "jsonrpc": "2.0"
  28. }
  29. ```
  30. The first entry in the result-array (`96`) is the method this response correlates with. `96` refers to "ResultTypeBroadcastTx", see [responses.go](https://github.com/tendermint/tendermint/blob/master/rpc/core/types/responses.go) for a complete overview.
  31. ### JSONRPC/HTTP
  32. JSONRPC requests can be POST'd to the root RPC endpoint via HTTP (e.g. `http://localhost:46657/`).
  33. Example request:
  34. ```json
  35. {
  36. "method": "broadcast_tx_sync",
  37. "jsonrpc": "2.0",
  38. "params": [ "abc" ],
  39. "id": "dontcare"
  40. }
  41. ```
  42. ### JSONRPC/websockets
  43. JSONRPC requests can be made via websocket. The websocket endpoint is at `/websocket`, e.g. `http://localhost:46657/websocket`. Asynchronous RPC functions like event `subscribe` and `unsubscribe` are only available via websockets.
  44. ### Endpoints
  45. An HTTP Get request to the root RPC endpoint (e.g. `http://localhost:46657`) shows a list of available endpoints.
  46. ```
  47. Available endpoints:
  48. http://localhost:46657/abci_info
  49. http://localhost:46657/dump_consensus_state
  50. http://localhost:46657/genesis
  51. http://localhost:46657/net_info
  52. http://localhost:46657/num_unconfirmed_txs
  53. http://localhost:46657/status
  54. http://localhost:46657/unconfirmed_txs
  55. http://localhost:46657/unsafe_flush_mempool
  56. http://localhost:46657/unsafe_stop_cpu_profiler
  57. http://localhost:46657/validators
  58. Endpoints that require arguments:
  59. http://localhost:46657/abci_query?path=_&data=_&prove=_
  60. http://localhost:46657/block?height=_
  61. http://localhost:46657/blockchain?minHeight=_&maxHeight=_
  62. http://localhost:46657/broadcast_tx_async?tx=_
  63. http://localhost:46657/broadcast_tx_commit?tx=_
  64. http://localhost:46657/broadcast_tx_sync?tx=_
  65. http://localhost:46657/commit?height=_
  66. http://localhost:46657/dial_seeds?seeds=_
  67. http://localhost:46657/subscribe?event=_
  68. http://localhost:46657/tx?hash=_&prove=_
  69. http://localhost:46657/unsafe_start_cpu_profiler?filename=_
  70. http://localhost:46657/unsafe_write_heap_profile?filename=_
  71. http://localhost:46657/unsubscribe?event=_
  72. ```
  73. ### tx
  74. Returns a transaction matching the given transaction hash.
  75. **Parameters**
  76. 1. hash - the transaction hash
  77. 2. prove - include a proof of the transaction inclusion in the block in the result (optional, default: false)
  78. **Returns**
  79. - `proof`: the `types.TxProof` object
  80. - `tx`: `[]byte` - the transaction
  81. - `tx_result`: the `abci.Result` object
  82. - `index`: `int` - index of the transaction
  83. - `height`: `int` - height of the block where this transaction was in
  84. **Example**
  85. ```bash
  86. curl -s 'http://localhost:46657/broadcast_tx_commit?tx="abc"' | jq .
  87. # {
  88. # "error": "",
  89. # "result": {
  90. # "hash": "2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF",
  91. # "log": "",
  92. # "data": "",
  93. # "code": 0
  94. # },
  95. # "id": "",
  96. # "jsonrpc": "2.0"
  97. # }
  98. curl -s 'http://localhost:46657/tx?hash=0x2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF' | jq .
  99. # {
  100. # "error": "",
  101. # "result": {
  102. # "proof": {
  103. # "Proof": {
  104. # "aunts": []
  105. # },
  106. # "Data": "YWJjZA==",
  107. # "RootHash": "2B8EC32BA2579B3B8606E42C06DE2F7AFA2556EF",
  108. # "Total": 1,
  109. # "Index": 0
  110. # },
  111. # "tx": "YWJjZA==",
  112. # "tx_result": {
  113. # "log": "",
  114. # "data": "",
  115. # "code": 0
  116. # },
  117. # "index": 0,
  118. # "height": 52
  119. # },
  120. # "id": "",
  121. # "jsonrpc": "2.0"
  122. # }
  123. ```
  124. ### More Examples
  125. See the various bash tests using curl in `test/`, and examples using the `Go` API in `rpc/client/`.