readSafe method

Future<LocalContractFunctionWithValuesAndOutputs> readSafe({
  1. required LocalContractFunctionWithValues function,
  2. BlockNum? atBlock,
})

Implementation

Future<LocalContractFunctionWithValuesAndOutputs> readSafe({
  required LocalContractFunctionWithValues function,
  BlockNum? atBlock,
}) async {
  if (function.stateMutability != StateMutability.pure &&
      function.stateMutability != StateMutability.view) {
    throw ArgumentError('Function is not view or pure');
  }

  final data = function.buildDataField();

  final String result =
      await rpc.call(contractAddress: contractAddress, data: data);

  final resultBuffer = result.hexToBytesWithPrefix;

  return LocalContractFunctionWithValuesAndOutputs.decode(
    data: resultBuffer,
    function: function,
  );
}