Fetch FIO Chain State Data

Overview

There are two ways to retrieve data from the FIO Chain:

  • FIO Chain Getters - purpose built getters that return most commonly used information from the FIO Chain.
  • get_table_rows - generic getter to query any table in FIO Chain state.

🚧

Table read limits

It's important to note that the FIO Chain API nodes have a limit on how many results are returned on a read query. This limit is dependent on variety of factors, including server technical specs, API version, size of the table, etc. When the limit is reached, your results will be returned even if not complete!

Therefore, you should never assume the query is returning the entire data set requested and validate the returned results set.

If large data set is expected, i.e. more than 500 results, you should consider using paged get_table_rows query method instead of the FIO Chain Getters, as those will experience the same limit issues and will only page through the limited set.

FIO Chain Getters

Paging

Most FIO Chain Getters take two paging parameters:

  • limit - number of results to return. If omitted, all is assumed. meaning all results will be attempted to be returned.
  • offset - number where the limit starts. If omitted, 0 is assumed, meaning the returned set will start at this first available.

In response, more parameter is returned which includes number of results which are still left following the last set you received.

Example:

  • Complete set has 1000 items
  • You request limit: 50, offset: 0
  • You get first 50 results and more: 950
  • To get next 50 results, set limit: 50, offset: 50
  • Repeat until more in response is 0

get_table_rows

Parameters

The core parameters are: code which denotes the specific FIO Chain contract, scope which will typically be same as code and table which denotes the specific table you want to query.

To constrain the response you may also pass in:

  • lower_bound and upper_bound denoting the search query start and stop
  • index_position denoting index to search
  • key_type denoting key type of index
  • limit denoting number of results to return

Paging

If you would like to page through a large dataset (beyond what can be returned in a single call), you must:

  • Read the primary index on the last record returned
  • Pass that value into lower_bound on a subsequent call
  • You will now receive items starting with that index

You should not assume you will receive all the records as specified in limit. Example:

  • Set contains 6,000 records
  • You set limit to 2,000 records
  • You only receive 200 records with last record primary index of 200
  • When you send the next query your lower_bound should be set to 201. If you set it to 2,000, thinking you just want the next 2,000 in the set you will be missing records 201-1999.

Examples