Native Layer Developer Guides
Learn more about developing DApps on the Native Layer:
Read data from contracts
exSat native layer stores data in tables, which are similar to database tables. Each table has a name and a set of fields. Tables are organized into scopes, which are defined by the smart contract that created the table.
To retrieve data from a table, you need to know its name, scope, and the name of the smart contract that created it. You can also specify a lower and upper bound to limit the amount of data returned.
To retrive data from a exSat native contract, all you need is :
A command-line interface to run curl commands.
Access to an exSat native layer RPC node. You could get the public RPC node here, or build your own RPC node.
The name of the contract, the table name, scope, and maybe the indexes.
use "get_table_rows" to get data from contract
The get_table_rows
function retrieves rows from a table. It takes the following parameters in JSON format:
code
must
string
The name of the smart contract that controls the provided table
table
must
string
The name of the table to query
scope
must
string
The account to which this data belongs
index_position
optional
string
Position of the index used, accepted parameters primary
, secondary
, tertiary
, fourth
, fifth
, sixth
, seventh
, eighth
, ninth
, tenth
key_type
optional
string
Type of key specified by index_position (for example - uint64_t
or name
)
encode_type
optional
string
representing the encoded type of the key_type parameter, either dec
or hex
, defaults to dec
.
lower_bound
optional
string
Filters results to return the first element that is not less than provided value in set
upper_bound
optional
string
Filters results to return the first element that is greater than provided value in set
limit
optional
integer <int32>Default: 10
Limit number of results returned.
reverse
optional
boolean Default: false
Reverse the order of returned results
show_payer
optional
boolean Default: false
Show RAM payer
Below is an example that retrieves rows from validators
table, owned by the endrmng.xsat
account and having endrmng.xsat
as scope
. which aims to get the registration information of the first validator.
In the example above:
The rows values are returned as JSON, set by the
json
parameter.The table is owned by the account
endrmng.xsat
, set by thecode
parameter.The table scope is
endrmng.xsat
, set by thescope
parameter.The table name is
validators
, set by thetable
parameter.The query uses the primary index to search the rows and starts from the lower bound index value, set by the
lower_bound
parameter.The function will fetch a maximum of 1 rows, set by the
limit
parameter.The retrieved rows will be in ascending order, set by the
reverse
parameter.
The get_table_rows Resultβ
The JSON returned by the get_table_rows
has the following structure:
The "rows"
field is an array of table row objects in JSON representation. The "more"
field indicates that there are additional rows beyond the ones returned. The "next_key"
field contains the key to be used as the lower bound in the next request to retrieve the next set of rows.
For example, the result from the previous section command contains one row, and looks similar to the one below (for privacy, the sensitive informations of the validator is replaced by "-":
Last updated