Query

The RootQueryBuilder class provides methods to query the Root Network.

The query capability is exposed from the root of the Transaction Builder class, enabling developers to query the chain without manually instantiating the class. it expects two parameters:

  • api: the trnApi to use for interaction.

  • walletAddress: the wallet address to use for interaction. Note: It should be the EOA address for the signer, not the FuturePass address.

Example:

const queryBuilder = new RootQueryBuilder(api, walletAddress);

The library currently supplies the following helper functions for querying the chain:

checkBalance()

Helper function used to get the balance of an asset. It can receive two parameters:

  • walletAddress: the wallet address to get the balance for. Wallet address is optional. When not provided, the wallet address of the instance will be used instead.

  • assetId: the asset ID to get the balance for.

Example:

const queryBuilder = new RootQueryBuilder(api, walletAddress);
queryBuilder.checkBalance({ walletAddress, assetId });

checkBalances()

Helper function used to check the balances of multiple assets for a given wallet address. It expects one parameter:

  • walletAddress and assetsId: an array of the [walletAddresses, assetId] pair to check balances for. Wallet address is optional. When not provided, the wallet address of the instance will be used instead.

This function throws an error if the API is not connected or if no wallet address and asset IDs are provided as parameters or by the instantiated class.

Example:

const queryBuilder = new RootQueryBuilder(api, walletAddress);

queryBuilder.checkBalance([
      { assetId: 1 },
      { assetId: 2 },
      { assetId: 3 },
      { assetId: 3172 },
      { assetId: 17508 },
    ]);

getAmountsIn()

Helper function used to get the amounts in for the given amount and asset ID. It expects three parameters:

  • amount: the amount to get the amounts in for.

  • assetId: the asset ID to get the amounts in for.

  • slippage: the slippage to use for the amounts in. Optional parameter. Defaults to value 5.

Slippage is optional, if not provided, a default of 5% will be used.

Example:

const queryBuilder = new RootQueryBuilder(api, walletAddress);
queryBuilder.getAmountsIn(amount, assetId);

getFuturePass()

Helper function used to get the FuturePass for the wallet address. It can receive one parameter:

  • walletAddress: the wallet address to get the FuturePass for.

This function throws an error if the API is not connected or if no wallet address is provided as parameter or by the instantiated class.

Example:

const queryBuilder = new RootQueryBuilder(api, walletAddress);
queryBuilder.getFuturePass(walletAddress);

readContract()

Reads a contract function and returns the decoded result. It can receive four parameters:

  • contractAddress: the contract address to read from.

  • abi: the ABI of the contract.

  • functionName: the function name to read.

  • args: the arguments to pass to the function. Optional parameter.

Example:

const queryBuilder = new RootQueryBuilder(api, walletAddress);
queryBuilder.readContract(contractAddress, abi, functionName);

Last updated

© 2023 -> ♾️