call method

Future<List> call({
  1. EthereumAddress? sender,
  2. required DeployedContract contract,
  3. required ContractFunction function,
  4. required List params,
  5. BlockNum? atBlock,
})

Calls a function defined in the smart contract and returns it's result.

The connected node must be able to calculate the result locally, which means that the call can't write any data to the blockchain. Doing that would require a transaction which can be sent via sendTransaction. As no data will be written, you can use the sender to specify any Ethereum address that would call that function. To use the address of a credential, call Credentials.extractAddress.

This function allows specifying a custom block mined in the past to get historical data. By default, BlockNum.current will be used.

Implementation

Future<List<dynamic>> call({
  EthereumAddress? sender,
  required DeployedContract contract,
  required ContractFunction function,
  required List<dynamic> params,
  BlockNum? atBlock,
}) async {
  final encodedResult = await callRaw(
    sender: sender,
    contract: contract.address,
    data: function.encodeCall(params),
    atBlock: atBlock,
  );

  return function.decodeReturnValues(encodedResult);
}