Skip to content

Torii Endpoints

API Version

  • Protocol: HTTP
  • Method: GET
  • Endpoint: /api_version

Responses:

200 OK: The current version of API used by Iroha returned as a JSON string. Grabbed from the genesis block's version, so at least a minimal subnet of 4 peers should be running and the genesis be submitted at the time of request.

json
"1"
"1"

Blocks Stream

  • Protocol: HTTP
  • Protocol Upgrade:`WebSocket
  • Endpoint: /block/stream

The client should send a BlockSubscriptionRequest to initiate communication after the WebSocket handshake. Then the server sends a BlockMessage. Messages are SCALE-encoded[1].

Via this endpoint, the client first provides the starting block number (i.e. height) in the subscription request. After sending the confirmation message, the server starts streaming all the blocks from the given block number up to the current block and continues to stream blocks as they are added to the blockchain.

Events

  • Protocol: HTTP
  • Protocol Upgrade: WebSocket
  • Endpoint: /events

After a handshake, the client should send an EventSubscriptionRequest. Then the server sends an EventMessage. Messages are SCALE-encoded[1:1].

Transaction Events

Transaction event statuses can be either Validating, Committed or Rejected.

Transaction statuses proceed from Validating to either Committed or Rejected. However, due to the distributed nature of the network, some peers might receive events out of order (e.g. Committed before Validating).

Some peers in the network may be offline for the validation round. If the client connects to them while they are offline, the peers might not respond with the Validating status. But when the offline peers come back online they will synchronize the blocks. They are then guaranteed to respond with the Committed (or Rejected) status depending on the information found in the block.

Health

  • Protocol: HTTP
  • Method: GET
  • Endpoint: /health

Responses with 200 OK and a current status of peer as a JSON string:

json
"Healthy"
"Healthy"

Metrics

  • Protocol: HTTP
  • Method: GET
  • Endpoint: /metrics

Responses:

200 OK reports 8 of 10 metrics:

Sample Prometheus metrics
bash
# HELP accounts User accounts registered at this time
# TYPE accounts gauge
accounts{domain="genesis"} 1
accounts{domain="wonderland"} 1
# HELP block_height Current block height
# TYPE block_height counter
block_height 1
# HELP connected_peers Total number of currently connected peers
# TYPE connected_peers gauge
connected_peers 0
# HELP domains Total number of domains
# TYPE domains gauge
domains 2
# HELP tx_amount average amount involved in a transaction on this peer
# TYPE tx_amount histogram
tx_amount_bucket{le="0.005"} 0
tx_amount_bucket{le="0.01"} 0
tx_amount_bucket{le="0.025"} 0
tx_amount_bucket{le="0.05"} 0
tx_amount_bucket{le="0.1"} 0
tx_amount_bucket{le="0.25"} 0
tx_amount_bucket{le="0.5"} 0
tx_amount_bucket{le="1"} 0
tx_amount_bucket{le="2.5"} 0
tx_amount_bucket{le="5"} 0
tx_amount_bucket{le="10"} 0
tx_amount_bucket{le="+Inf"} 2
tx_amount_sum 26
tx_amount_count 2
# HELP txs Transactions committed
# TYPE txs counter
txs{type="accepted"} 1
txs{type="rejected"} 0
txs{type="total"} 1
# HELP uptime_since_genesis_ms Network up-time, from creation of the genesis block
# TYPE uptime_since_genesis_ms gauge
uptime_since_genesis_ms 54572974
# HELP view_changes Number of view_changes in the current round
# TYPE view_changes gauge
view_changes 0
# HELP accounts User accounts registered at this time
# TYPE accounts gauge
accounts{domain="genesis"} 1
accounts{domain="wonderland"} 1
# HELP block_height Current block height
# TYPE block_height counter
block_height 1
# HELP connected_peers Total number of currently connected peers
# TYPE connected_peers gauge
connected_peers 0
# HELP domains Total number of domains
# TYPE domains gauge
domains 2
# HELP tx_amount average amount involved in a transaction on this peer
# TYPE tx_amount histogram
tx_amount_bucket{le="0.005"} 0
tx_amount_bucket{le="0.01"} 0
tx_amount_bucket{le="0.025"} 0
tx_amount_bucket{le="0.05"} 0
tx_amount_bucket{le="0.1"} 0
tx_amount_bucket{le="0.25"} 0
tx_amount_bucket{le="0.5"} 0
tx_amount_bucket{le="1"} 0
tx_amount_bucket{le="2.5"} 0
tx_amount_bucket{le="5"} 0
tx_amount_bucket{le="10"} 0
tx_amount_bucket{le="+Inf"} 2
tx_amount_sum 26
tx_amount_count 2
# HELP txs Transactions committed
# TYPE txs counter
txs{type="accepted"} 1
txs{type="rejected"} 0
txs{type="total"} 1
# HELP uptime_since_genesis_ms Network up-time, from creation of the genesis block
# TYPE uptime_since_genesis_ms gauge
uptime_since_genesis_ms 54572974
# HELP view_changes Number of view_changes in the current round
# TYPE view_changes gauge
view_changes 0

Learn how to use metrics.

Query

  • Protocol: HTTP
  • Method: POST
  • Endpoint: /query
  • Expects:
    • Body: SCALE-encoded[1:2] VersionedSignedQuery
    • Query parameters:
      • start: An optional parameter in queries where results can be indexed. Use to return results from a specified point. Results are ordered by id, which uses Rust's PartialOrd and Ord traits.
      • limit: An optional parameter in queries where results can be indexed. Use to return a specific number of results.
      • sort_by_metadata_key: An optional parameter in queries. Use to sort results containing metadata with a given key.
      • fetch_size: An optional parameter in queries. Use to specify the exact number of results returned by a query.

Responses:

ResponseStatusBody
Success200VersionedBatchedResponse<Value>
Conversion Error400QueryExecutionFail::Conversion(String)
Evaluate Error400QueryExecutionFail::Evaluate(String)
Signature Error401QueryExecutionFail::Signature(String)
Permission Error403QueryExecutionFail::Permission(String)
Find Error404QueryExecutionFail::Find(FindError)

Account Not Found 404

Whether each prerequisite object was found and FindError:

DomainAccountFindError
N-FindError::Domain(DomainId)
YNFindError::Account(AccountId)

Asset Not Found 404

Whether each prerequisite object was found and FindError:

DomainAccountAsset DefinitionAssetFindError
N---FindError::Domain(DomainId)
YN--FindError::Account(AccountId)
Y-N-FindError::AssetDefinition(AssetDefinitionId)
YYYNFindError::Asset(AssetId)

Status

  • Protocol: HTTP
  • Method: GET
  • Endpoint: /status
  • Expects: an optional Accept: application/x-parity-scale request header to encode response with SCALE[1:3]. Otherwise, will fall back to application/json.
  • Responses: with Content-Type set either to application/json or application/x-parity-scale, and an accordingly encoded response body.

Response body is of the following Status structure:

rust
struct Status {
    /// Number of connected peers, except for the reporting peer itself
    peers: u64,
    /// Number of committed blocks
    blocks: u64,
    /// Number of accepted transactions
    txs_accepted: u64,
    /// Number of rejected transactions
    txs_rejected: u64,
    /// Uptime since genesis block creation
    uptime: Uptime,
    /// Number of view changes in the current round
    view_changes: u64,
    /// Number of the transactions in the queue
    queue_size: u64,
}

struct Uptime {
    secs: u64,
    nanos: u32
}
struct Status {
    /// Number of connected peers, except for the reporting peer itself
    peers: u64,
    /// Number of committed blocks
    blocks: u64,
    /// Number of accepted transactions
    txs_accepted: u64,
    /// Number of rejected transactions
    txs_rejected: u64,
    /// Uptime since genesis block creation
    uptime: Uptime,
    /// Number of view changes in the current round
    view_changes: u64,
    /// Number of the transactions in the queue
    queue_size: u64,
}

struct Uptime {
    secs: u64,
    nanos: u32
}

JSON Precision Lost

Almost all fields in the Status structure are 64-bit integers, and they are encoded in JSON as-is. Since native JSON's number type according to the specification effectively is f64, the precision might be lost on deserialization, for example, in JavaScript's JSON.parse. For more details, see related issue.

Compact Form in SCALE

Fields with type u64 serialized in the Compact form.

Sample responses

These samples represent the same data:

json
{
  "peers": 4,
  "blocks": 5,
  "txs_accepted": 31,
  "txs_rejected": 3,
  "uptime": {
    "secs": 5,
    "nanos": 937000000
  },
  "view_changes": 2,
  "queue_size": 18
}
{
  "peers": 4,
  "blocks": 5,
  "txs_accepted": 31,
  "txs_rejected": 3,
  "uptime": {
    "secs": 5,
    "nanos": 937000000
  },
  "view_changes": 2,
  "queue_size": 18
}
10 14 7C 0C 14 40 7C D9 37 08 48
10 14 7C 0C 14 40 7C D9 37 08 48

Sub-routing

To obtain the value of a specific field, one can append the name of the field to the path, e.g. /status/peers. This returns the corresponding JSON value.

json
4
4
json
{
  "secs": 5,
  "nanos": 937000000
}
{
  "secs": 5,
  "nanos": 937000000
}
json
5
5

Transaction

Responses:

StatusDescription
200Transaction Accepted (But not guaranteed to have passed consensus yet)
400Transaction Rejected (Malformed)
401Transaction Rejected (Improperly signed)

  1. For more information on Parity SCALE Codec check Substrate Dev Hub and codec's GitHub repository.

    ↩︎ ↩︎ ↩︎ ↩︎ ↩︎