Native Layer Developer Guides

Learn more about developing DApps on the Native Layer:

You can access the native layer using the RPC node provided by exSat or by running your own RPC node.

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.

curl --request POST \
--url https://rpc-sg.exsat.network/v1/chain/get_table_rows \
--header 'content-type: application/json'  \
--data '{ 
"json": true, 
"code": "endrmng.xsat", 
"scope": "endrmng.xsat", 
"table": "validators", 
"lower_bound": "0", 
"limit": 1, 
"reverse": false 
}'

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 the code parameter.

  • The table scope is endrmng.xsat, set by the scope parameter.

  • The table name is validators, set by the table 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:

{
  "rows": [
    { },
    ...
    { }
  ],
  "more": true,
  "next_key": ""
}

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 "-":

{
    "rows": [
        {
            "owner": "-----.sat",
            "reward_recipient": "erc2o.xsat",
            "memo": "0x--------------------",
            "commission_rate": 1000,
            "quantity": "0.00000000 BTC",
            "qualification": "0.00000000 BTC",
            "xsat_quantity": "0.00000000 XSAT",
            "donate_rate": 0,
            "total_donated": "0.00000000 XSAT",
            "stake_acc_per_share": "0",
            "consensus_acc_per_share": "0",
            "staking_reward_unclaimed": "0.00000000 XSAT",
            "staking_reward_claimed": "0.00000000 XSAT",
            "consensus_reward_unclaimed": "0.00000000 XSAT",
            "consensus_reward_claimed": "0.00000000 XSAT",
            "total_consensus_reward": "0.00000000 XSAT",
            "consensus_reward_balance": "0.00000000 XSAT",
            "total_staking_reward": "0.00000000 XSAT",
            "staking_reward_balance": "0.00000000 XSAT",
            "latest_staking_time": "1970-01-01T00:00:00",
            "latest_reward_block": 0,
            "latest_reward_time": "1970-01-01T00:00:00",
            "disabled_staking": 0
        }
    ],
    "more": true,
    "next_key": "3815492618318908816"
}

Last updated