Skip to main content

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:

  1. URI over HTTP,
  2. JSON-RPC over HTTP.
  3. 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.

Info

Node Status

Get node status including node info, pubkey, latest block hash, app hash, block height and time.

Responses

Response samples

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

Node health

Get node health. Returns empty result (200 OK) on success, no response - in case of an error.

Responses

Response samples

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

Network

Network information

Get network info.

Responses

Response samples

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

Block

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

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

Validator

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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

Consensus

Get consensus state

Get consensus state.

Not safe to call from inside the ABCI application during a block execution.

Responses

Response samples

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

Transactions

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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    },
  • "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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    },
  • "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

Content type
application/json
{
  • "error": "",
  • "result": {
    },
  • "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

Content type
application/json
{
  • "error": "",
  • "result": {
    },
  • "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

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

num_unconfirmed_txs

Get data about unconfirmed transactions

Responses

Response samples

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}

Websocket

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

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

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

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

Unsubscribe from all events via WebSocket

Unsubscribe from all events via WebSocket

Responses

Response samples

Content type
application/json
{
  • "id": 0,
  • "jsonrpc": "2.0",
  • "result": {
    }
}

ABCI

Get some info about the application.

Get some info about the application.

Responses

Response samples

Content type
application/json
{
  • "jsonrpc": "2.0",
  • "id": 0,
  • "result": {
    }
}