CUDOS RPC (1.0.0)
Download OpenAPI specification:Download
REST interface for state queries and transactions.
Base URLs
CUDOS Mainnet RPC https://rpc.cudos.org
CUDOS Testnet RPC https://sentry1.gcp-uscentral1.cudos.org:36657/
CUDOS Localhost RPC https://localhost:26657
Supports the following RPC protocols:
- URI over HTTP,
- JSON-RPC over HTTP.
- JSON-RPC over websockets
How to configure?
Configure network and parameters in config.toml or using --rpc.X
command line flag.
RPC can be configured by tuning parameters under [rpc]
table in the
$TMHOME/config/config.toml
file or by using the --rpc.X
command-line
flags.
The default rpc listen address is tcp://0.0.0.0:26657
.
To set another address, set the laddr
config parameter to desired value.
CORS (Cross-Origin Resource Sharing) can be enabled by setting
cors_allowed_origins
, cors_allowed_methods
, cors_allowed_headers
config parameters.
Arguments
Arguments which expect strings or byte arrays may be passed as quoted
strings, like "abc"
or as 0x
-prefixed strings, like 0x616263
.
URI/HTTP
A REST like interface.
curl localhost:26657/block?height=45
JSONRPC/HTTP
POST JSONRPC requests to the root RPC endpoint via HTTP.
curl --header "Content-Type: application/json" --request POST --data '{"method": "block", "params": ["5"], "id": 1}' localhost:26657
JSONRPC/websockets
JSONRPC requests can be also made via websocket.
The websocket endpoint is at /websocket
, e.g. localhost:26657/websocket
.
Asynchronous RPC functions like event subscribe
and unsubscribe
are
only available via websockets.
Node Status
Get node status including node info, pubkey, latest block hash, app hash, block height and time.
Responses
Response samples
- 200
- 500
{- "id": 0,
- "jsonrpc": "2.0",
- "result": {
- "node_info": {
- "protocol_version": {
- "p2p": "7",
- "block": "10",
- "app": "0"
}, - "id": "5576458aef205977e18fd50b274e9b5d9014525a",
- "listen_addr": "tcp:0.0.0.0:26656",
- "network": "cosmoshub-2",
- "version": "0.32.1",
- "channels": "4020212223303800",
- "moniker": "moniker-node",
- "other": {
- "tx_index": "on",
- "rpc_address": "tcp:0.0.0.0:26657"
}
}, - "sync_info": {
- "latest_block_hash": "790BA84C3545FCCC49A5C629CEE6EA58A6E875C3862175BDC11EE7AF54703501",
- "latest_app_hash": "C9AEBB441B787D9F1D846DE51F3826F4FD386108B59B08239653ABF59455C3F8",
- "latest_block_height": "1262196",
- "latest_block_time": "2019-08-01T11:52:22.818762194Z",
- "earliest_block_hash": "790BA84C3545FCCC49A5C629CEE6EA58A6E875C3862175BDC11EE7AF54703501",
- "earliest_app_hash": "C9AEBB441B787D9F1D846DE51F3826F4FD386108B59B08239653ABF59455C3F8",
- "earliest_block_height": "1262196",
- "earliest_block_time": "2019-08-01T11:52:22.818762194Z",
- "catching_up": false
}, - "validator_info": {
- "address": "5D6A51A8E9899C44079C6AF90618BA0369070E6E",
- "pub_key": {
- "type": "tendermint/PubKeyEd25519",
- "value": "A6DoBUypNtUAyEHWtQ9bFjfNg8Bo9CrnkUGl6k6OHN4="
}, - "voting_power": "0"
}
}
}
Response samples
- 200
- 500
{- "id": 0,
- "jsonrpc": "2.0",
- "result": {
- "listening": true,
- "listeners": [
- "Listener(@)"
], - "n_peers": "1",
- "peers": [
- {
- "node_info": {
- "protocol_version": {
- "p2p": "7",
- "block": "10",
- "app": "0"
}, - "id": "5576458aef205977e18fd50b274e9b5d9014525a",
- "listen_addr": "tcp:0.0.0.0:26656",
- "network": "cosmoshub-2",
- "version": "0.32.1",
- "channels": "4020212223303800",
- "moniker": "moniker-node",
- "other": {
- "tx_index": "on",
- "rpc_address": "tcp:0.0.0.0:26657"
}
}, - "is_outbound": true,
- "connection_status": {
- "Duration": "168901057956119",
- "SendMonitor": {
- "Active": true,
- "Start": "2019-07-31T14:31:28.66Z",
- "Duration": "168901060000000",
- "Idle": "168901040000000",
- "Bytes": "5",
- "Samples": "1",
- "InstRate": "0",
- "CurRate": "0",
- "AvgRate": "0",
- "PeakRate": "0",
- "BytesRem": "0",
- "TimeRem": "0",
- "Progress": 0
}, - "RecvMonitor": {
- "Active": true,
- "Start": "2019-07-31T14:31:28.66Z",
- "Duration": "168901060000000",
- "Idle": "168901040000000",
- "Bytes": "5",
- "Samples": "1",
- "InstRate": "0",
- "CurRate": "0",
- "AvgRate": "0",
- "PeakRate": "0",
- "BytesRem": "0",
- "TimeRem": "0",
- "Progress": 0
}, - "Channels": [
- {
- "ID": 48,
- "SendQueueCapacity": "1",
- "SendQueueSize": "0",
- "Priority": "5",
- "RecentlySent": "0"
}
]
}, - "remote_ip": "95.179.155.35"
}
]
}
}
Get block at a specified height
Get Block.
query Parameters
height | integer Default: 0 Example: height=1 height to return. If no height is provided, it will fetch the latest block. |
Responses
Response samples
- 200
- 500
{- "id": 0,
- "jsonrpc": "2.0",
- "result": {
- "block_id": {
- "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7",
- "parts": {
- "total": 1,
- "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD"
}, - "components": null,
- "tags": null
}, - "block": {
- "header": {
- "version": {
- "block": "10",
- "app": "0"
}, - "chain_id": "cosmoshub-2",
- "height": "12",
- "time": "2019-04-22T17:01:51.701356223Z",
- "last_block_id": {
- "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7",
- "parts": {
- "total": 1,
- "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD"
}, - "components": null,
- "tags": null
}, - "last_commit_hash": "21B9BC845AD2CB2C4193CDD17BFC506F1EBE5A7402E84AD96E64171287A34812",
- "data_hash": "970886F99E77ED0D60DA8FCE0447C2676E59F2F77302B0C4AA10E1D02F18EF73",
- "validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0",
- "next_validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0",
- "consensus_hash": "0F2908883A105C793B74495EB7D6DF2EEA479ED7FC9349206A65CB0F9987A0B8",
- "app_hash": "223BF64D4A01074DC523A80E76B9BBC786C791FB0A1893AC5B14866356FCFD6C",
- "last_results_hash": "",
- "evidence_hash": "",
- "proposer_address": "D540AB022088612AC74B287D076DBFBC4A377A2E"
}, - "data": [
- "yQHwYl3uCkKoo2GaChRnd+THLQ2RM87nEZrE19910Z28ABIUWW/t8AtIMwcyU0sT32RcMDI9GF0aEAoFdWF0b20SBzEwMDAwMDASEwoNCgV1YXRvbRIEMzEwMRCd8gEaagom61rphyEDoJPxlcjRoNDtZ9xMdvs+lRzFaHe2dl2P5R2yVCWrsHISQKkqX5H1zXAIJuC57yw0Yb03Fwy75VRip0ZBtLiYsUqkOsPUoQZAhDNP+6LY+RUwz/nVzedkF0S29NZ32QXdGv0="
], - "evidence": [
- {
- "type": "string",
- "height": 0,
- "time": 0,
- "total_voting_power": 0,
- "validator": {
- "pub_key": {
- "type": "tendermint/PubKeyEd25519",
- "value": "A6DoBUypNtUAyEHWtQ9bFjfNg8Bo9CrnkUGl6k6OHN4="
}, - "voting_power": 0,
- "address": "string"
}
}
], - "last_commit": {
- "height": 0,
- "round": 0,
- "block_id": {
- "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7",
- "parts": {
- "total": 1,
- "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD"
}, - "components": null,
- "tags": null
}, - "signatures": [
- {
- "type": 2,
- "height": "1262085",
- "round": 0,
- "block_id": {
- "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7",
- "parts": {
- "total": 1,
- "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD"
}, - "components": null,
- "tags": null
}, - "timestamp": "2019-08-01T11:39:38.867269833Z",
- "validator_address": "000001E443FD237E4B616E2FA69DF4EE3D49A94F",
- "validator_index": 0,
- "signature": "DBchvucTzAUEJnGYpNvMdqLhBAHG4Px8BsOBB3J3mAFCLGeuG7uJqy+nVngKzZdPhPi8RhmE/xcw/M9DOJjEDg=="
}
]
}
}
}
}
Get block results at a specified height
Get block_results. When the discard_abci_responses
storage flag is
enabled, this endpoint will return an error.
query Parameters
height | integer Default: 0 Example: height=1 height to return. If no height is provided, it will fetch informations regarding the latest block. |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "height": "12",
- "txs_results": [
- {
- "code": "0",
- "data": "",
- "log": "not enough gas",
- "info": "",
- "gas_wanted": "100",
- "gas_used": "100",
- "events": [
- {
- "type": "app",
- "attributes": [
- {
- "key": "YWN0aW9u",
- "value": "c2VuZA==",
- "index": false
}
]
}
], - "codespace": "ibc"
}
], - "begin_block_events": [
- {
- "type": "app",
- "attributes": [
- {
- "key": "YWN0aW9u",
- "value": "c2VuZA==",
- "index": false
}
]
}
], - "end_block": [
- {
- "type": "app",
- "attributes": [
- {
- "key": "YWN0aW9u",
- "value": "c2VuZA==",
- "index": false
}
]
}
], - "validator_updates": [
- {
- "pub_key": {
- "type": "tendermint/PubKeyEd25519",
- "value": "9tK9IT+FPdf2qm+5c2qaxi10sWP+3erWTKgftn2PaQM="
}, - "power": "300"
}
], - "consensus_params_updates": {
- "block": {
- "max_bytes": "22020096",
- "max_gas": "1000",
- "time_iota_ms": "1000"
}, - "evidence": {
- "max_age": "100000"
}, - "validator": {
- "pub_key_types": [
- "ed25519"
]
}
}
}
}
Get commit results at a specified height
Get Commit.
query Parameters
height | integer Default: 0 Example: height=1 height to return. If no height is provided, it will fetch commit information from the latest block. |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "signed_header": {
- "header": {
- "version": {
- "block": "10",
- "app": "0"
}, - "chain_id": "cosmoshub-2",
- "height": "12",
- "time": "2019-04-22T17:01:51.701356223Z",
- "last_block_id": {
- "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7",
- "parts": {
- "total": 1,
- "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD"
}, - "components": null,
- "tags": null
}, - "last_commit_hash": "21B9BC845AD2CB2C4193CDD17BFC506F1EBE5A7402E84AD96E64171287A34812",
- "data_hash": "970886F99E77ED0D60DA8FCE0447C2676E59F2F77302B0C4AA10E1D02F18EF73",
- "validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0",
- "next_validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0",
- "consensus_hash": "0F2908883A105C793B74495EB7D6DF2EEA479ED7FC9349206A65CB0F9987A0B8",
- "app_hash": "223BF64D4A01074DC523A80E76B9BBC786C791FB0A1893AC5B14866356FCFD6C",
- "last_results_hash": "",
- "evidence_hash": "",
- "proposer_address": "D540AB022088612AC74B287D076DBFBC4A377A2E"
}, - "commit": {
- "height": "1311801",
- "round": 0,
- "block_id": {
- "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7",
- "parts": {
- "total": 1,
- "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD"
}, - "components": null,
- "tags": null
}, - "signatures": [
- {
- "block_id_flag": 2,
- "validator_address": "000001E443FD237E4B616E2FA69DF4EE3D49A94F",
- "timestamp": "2019-04-22T17:01:58.376629719Z",
- "signature": "14jaTQXYRt8kbLKEhdHq7AXycrFImiLuZx50uOjs2+Zv+2i7RTG/jnObD07Jo2ubZ8xd7bNBJMqkgtkd0oQHAw=="
}
]
}
}, - "canonical": true
}
}
Get validator set at a specified height
Get Validators. Validators are sorted by voting power.
query Parameters
height | integer Default: 0 Example: height=1 height to return. If no height is provided, it will fetch validator set which corresponds to the latest block. |
page | integer Default: 1 Example: page=1 Page number (1-based) |
per_page | integer Default: 30 Example: per_page=30 Number of entries per page (max: 100) |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "block_height": "55",
- "validators": [
- {
- "address": "000001E443FD237E4B616E2FA69DF4EE3D49A94F",
- "pub_key": {
- "type": "tendermint/PubKeyEd25519",
- "value": "9tK9IT+FPdf2qm+5c2qaxi10sWP+3erWTKgftn2PaQM="
}, - "voting_power": "239727",
- "proposer_priority": "-11896414"
}
], - "count": "1",
- "total": "25"
}
}
Get consensus state
Get consensus state.
Not safe to call from inside the ABCI application during a block execution.
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "round_state": {
- "height/round/step": "1262197/0/8",
- "start_time": "2019-08-01T11:52:38.962730289Z",
- "proposal_block_hash": "634ADAF1F402663BEC2ABC340ECE8B4B45AA906FA603272ACC5F5EED3097E009",
- "locked_block_hash": "634ADAF1F402663BEC2ABC340ECE8B4B45AA906FA603272ACC5F5EED3097E009",
- "valid_block_hash": "634ADAF1F402663BEC2ABC340ECE8B4B45AA906FA603272ACC5F5EED3097E009",
- "height_vote_set": [
- {
- "round": 0,
- "prevotes": [
- "Vote{0:000001E443FD 1262197/00/1(Prevote) 634ADAF1F402 7BB974E1BA40 @ 2019-08-01T11:52:35.513572509Z}",
- "nil-Vote"
], - "prevotes_bit_array": "BA{100:xxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} 169753436/170151262 = 1.00",
- "precommits": [
- "Vote{5:18C78D135C9D 1262197/00/2(Precommit) 634ADAF1F402 8B5EFFFEABCD @ 2019-08-01T11:52:36.25600005Z}",
- "nil-Vote"
], - "precommits_bit_array": "BA{100:xxxxxx_xxxxx_xxxx_x_xxx_xx_xx_xx__x_x_x__xxxxxxxxxxxxxx_xxxx_xx_xxxxxx_xxxxxxxx_xxxx_xxx_x_xxxx__xxx} 118726247/170151262 = 0.70"
}
], - "proposer": {
- "address": "D540AB022088612AC74B287D076DBFBC4A377A2E",
- "index": 0
}
}
}
}
Get consensus parameters
Get consensus parameters.
query Parameters
height | integer Default: 0 Example: height=1 height to return. If no height is provided, it will fetch commit informations regarding the latest block. |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "block_height": "1",
- "consensus_params": {
- "block": {
- "max_bytes": "22020096",
- "max_gas": "1000",
- "time_iota_ms": "1000"
}, - "evidence": {
- "max_age": "100000"
}, - "validator": {
- "pub_key_types": [
- "ed25519"
]
}
}
}
}
broadcast_tx_sync
Returns CheckTx. Does not wait for DeliverTx result. Subscribe to websocket events to be sure a tx is included in a block. If you don't receive a notification, try sending to another node.
query Parameters
tx required | string Example: tx=378 Transaction ID |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "code": "0",
- "data": "",
- "log": "",
- "codespace": "ibc",
- "hash": "0D33F2F03A5234F38706E43004489E061AC40A2E"
}, - "error": ""
}
broadcast_tx_async
Returns immediately with no response. Subscribe to websocket events to get CheckTx and DeliverTx response. If you haven't received anything after a couple of blocks, resend it. If the same happens again, send it to a different other node.
query Parameters
tx required | string Example: tx=538 Transaction ID |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "code": "0",
- "data": "",
- "log": "",
- "codespace": "ibc",
- "hash": "0D33F2F03A5234F38706E43004489E061AC40A2E"
}, - "error": ""
}
broadcast_tx_commit
Returns with the responses from CheckTx and DeliverTx. USE ONLY FOR TESTING AND DEVELOPMENT. In production, use BroadcastTxSync or BroadcastTxAsync. Subscribe to Websocket events. CONTRACT: only returns error if mempool.CheckTx() errs or if there is a timeout waiting for tx to commit. If CheckTx or DeliverTx fail, no error is returned but the returned result contains a non-OK ABCI code.
query Parameters
transaction required | string Example: transaction=426 Transaction ID |
Responses
Response samples
- 200
- 500
{- "error": "",
- "result": {
- "height": "26682",
- "hash": "75CA0F856A4DA078FC4911580360E70CEFB2EBEE",
- "deliver_tx": {
- "log": "",
- "data": "",
- "code": "0"
}, - "check_tx": {
- "log": "",
- "data": "",
- "code": "0"
}
}, - "id": 0,
- "jsonrpc": "2.0"
}
check_tx
Checks the transaction without executing it. The transaction is NOT added to the mempool.
query Parameters
tx required | string Example: tx=736 Transaction ID |
Responses
Response samples
- 200
- 500
{- "error": "",
- "result": {
- "code": "0",
- "data": "",
- "log": "",
- "info": "",
- "gas_wanted": "1",
- "gas_used": "0",
- "events": [
- {
- "type": "app",
- "attributes": [
- {
- "key": "YWN0aW9u",
- "value": "c2VuZA==",
- "index": false
}
]
}
], - "codespace": "bank"
}, - "id": 0,
- "jsonrpc": "2.0"
}
unconfirmed_txs
Get list of unconfirmed transactions
query Parameters
limit | integer Default: 30 Example: limit=3 Returns a list of unconfirmed transactions. Maximum number of unconfirmed transactions to return (max 100) |
Responses
Response samples
- 200
- 500
{- "jsonrpc": "2.0",
- "id": 0,
- "result": {
- "n_txs": "82",
- "total": "82",
- "total_bytes": "19974",
- "txs": [
- "gAPwYl3uCjCMTXENChSMnIkb5ZpYHBKIZqecFEV2tuZr7xIUA75/FmYq9WymsOBJ0XSJ8yV8zmQKMIxNcQ0KFIyciRvlmlgcEohmp5wURXa25mvvEhQbrvwbvlNiT+Yjr86G+YQNx7kRVgowjE1xDQoUjJyJG+WaWBwSiGannBRFdrbma+8SFK2m+1oxgILuQLO55n8mWfnbIzyPCjCMTXENChSMnIkb5ZpYHBKIZqecFEV2tuZr7xIUQNGfkmhTNMis4j+dyMDIWXdIPiYKMIxNcQ0KFIyciRvlmlgcEohmp5wURXa25mvvEhS8sL0D0wwgGCItQwVowak5YB38KRIUCg4KBXVhdG9tEgUxMDA1NBDoxRgaagom61rphyECn8x7emhhKdRCB2io7aS/6Cpuq5NbVqbODmqOT3jWw6kSQKUresk+d+Gw0BhjiggTsu8+1voW+VlDCQ1GRYnMaFOHXhyFv7BCLhFWxLxHSAYT8a5XqoMayosZf9mANKdXArA="
]
}
}
Subscribe to Websocket events
Subscribe to events via WebSocket.
Perform queries using the form: "condition AND condition ..." (no OR at the moment).
Condition has a form: "key operation operand"
Key is a string with a restricted set of possible symbols ( \t\n\r\()"'=>< are not allowed).
Operation can be "=", "<", "<=", ">", ">=", "CONTAINS" AND "EXISTS". operand can be a string (escaped with single quotes), number, date or time.
Examples
tm.event = 'NewBlock' # new blocks
tm.event = 'CompleteProposal' # node got a complete proposal
tm.event = 'Tx' AND tx.hash = 'XYZ' # single transaction
tm.event = 'Tx' AND tx.height = 5 # all txs of the fifth block
tx.height = 5 # all txs of the fifth block
Tendermint provides a few predefined keys: tm.event
, tx.hash
and tx.height
.
NOTE: For transactions, you can define additional keys by providing events with DeliverTx response.
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/pubsub/query"
)
abci.ResponseDeliverTx{
Events: []abci.Event{
{
Type: "rewards.withdraw",
Attributes: abci.EventAttribute{
{Key: []byte("address"), Value: []byte("AddrA"), Index: true},
{Key: []byte("source"), Value: []byte("SrcX"), Index: true},
{Key: []byte("amount"), Value: []byte("..."), Index: true},
{Key: []byte("balance"), Value: []byte("..."), Index: true},
},
},
{
Type: "rewards.withdraw",
Attributes: abci.EventAttribute{
{Key: []byte("address"), Value: []byte("AddrB"), Index: true},
{Key: []byte("source"), Value: []byte("SrcY"), Index: true},
{Key: []byte("amount"), Value: []byte("..."), Index: true},
{Key: []byte("balance"), Value: []byte("..."), Index: true},
},
},
{
Type: "transfer",
Attributes: abci.EventAttribute{
{Key: []byte("sender"), Value: []byte("AddrC"), Index: true},
{Key: []byte("recipient"), Value: []byte("AddrD"), Index: true},
{Key: []byte("amount"), Value: []byte("..."), Index: true},
},
},
},
}
All events are indexed by a composite key of the form {eventType}.{evenAttrKey}. In the above examples, the following keys would be indexed:
- rewards.withdraw.address
- rewards.withdraw.source
- rewards.withdraw.amount
- rewards.withdraw.balance
- transfer.sender
- transfer.recipient
- transfer.amount
Multiple event types with duplicate keys are allowed and are meant to
categorize unique and distinct events. In the above example, all events
indexed under the key
rewards.withdraw.address
will have the following values stored and queryable: - AddrA
- AddrB To create a query for txs where address AddrA withdrew rewards: query.MustParse("tm.event = 'Tx' AND rewards.withdraw.address = 'AddrA'") To create a query for txs where address AddrA withdrew rewards from source Y: query.MustParse("tm.event = 'Tx' AND rewards.withdraw.address = 'AddrA' AND rewards.withdraw.source = 'Y'") To create a query for txs where AddrA transferred funds: query.MustParse("tm.event = 'Tx' AND transfer.sender = 'AddrA'") The following queries would return no results: query.MustParse("tm.event = 'Tx' AND transfer.sender = 'AddrZ'") query.MustParse("tm.event = 'Tx' AND rewards.withdraw.address = 'AddrZ'") query.MustParse("tm.event = 'Tx' AND rewards.withdraw.source = 'W'")
See list of all possible events here https://godoc.org/github.com/tendermint/tendermint/types#pkg-constants
For complete query syntax, check out https://godoc.org/github.com/tendermint/tendermint/libs/pubsub/query.
import rpchttp "github.com/tendermint/rpc/client/http"
import "github.com/tendermint/tendermint/types"
client := rpchttp.New("tcp:0.0.0.0:26657", "/websocket")
err := client.Start()
if err != nil {
handle error
}
defer client.Stop()
ctx, cancel := context.WithTimeout(context.Background(), 1 * time.Second)
defer cancel()
query := "tm.event = 'Tx' AND tx.height = 3"
txs, err := client.Subscribe(ctx, "test-client", query)
if err != nil {
handle error
}
go func() {
for e := range txs {
fmt.Println("got ", e.Data.(types.EventDataTx))
}
}()
NOTE: if you're not reading events fast enough your subsciption may be terminated.
query Parameters
query required | string Example: query=tm.event = 'Tx' AND tx.height = 5 query is a string, which has a form: "condition AND condition ..." (no OR at the moment). condition has a form: "key operation operand". key is a string with a restricted set of possible symbols ( \t\n\r\()"'=>< are not allowed). operation can be "=", "<", "<=", ">", ">=", "CONTAINS". operand can be a string (escaped with single quotes), number, date or time. |
Responses
Response samples
- 200
- 500
{- "id": 0,
- "jsonrpc": "2.0",
- "result": {
- "property1": null,
- "property2": null
}
}
Unsubscribe from events on Websocket
client := rpchttp.New("tcp:0.0.0.0:26657", "/websocket")
err := client.Start()
if err != nil {
handle error
}
defer client.Stop()
query := "tm.event = 'Tx' AND tx.height = 3"
err = client.Unsubscribe(context.Background(), "test-client", query)
if err != nil {
handle error
}
query Parameters
query required | string Example: query=tm.event = 'Tx' AND tx.height = 5 query is a string, which has a form: "condition AND condition ..." (no OR at the moment). condition has a form: "key operation operand". key is a string with a restricted set of possible symbols ( \t\n\r\()"'=>< are not allowed). operation can be "=", "<", "<=", ">", ">=", "CONTAINS". operand can be a string (escaped with single quotes), number, date or time. |
Responses
Response samples
- 200
- 500
{- "id": 0,
- "jsonrpc": "2.0",
- "result": {
- "property1": null,
- "property2": null
}
}