call method

Future<EthereumData?> call(
  1. EthereumAddress? address,
  2. EthereumDefaultBlock? block, {
  3. EthereumAddress? from,
  4. int? gas,
  5. int? gasPrice,
  6. int? value,
  7. EthereumData? data,
})

Call Executes a new message call immediately without creating a transaction on the block chain. address: The address the transaction is sent to. from: (optional) The address the transaction is sent from. gas: (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions. gasPrice: (optional) Integer of the gasPrice used for each paid gas value: (optional) Integer of the value send with this transaction data: (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI block: default block parameter Returns the return value of executed contract.

Implementation

Future<EthereumData?> call(
    EthereumAddress? address, EthereumDefaultBlock? block,
    {EthereumAddress? from,
    int? gas,
    int? gasPrice,
    int? value,
    EthereumData? data}) async {
  if (address == null) {
    throw ArgumentError.notNull('Ethereum::call - address');
  }
  if (block == null) {
    throw ArgumentError.notNull('Ethereum::call - block');
  }
  const method = EthereumRpcMethods.call;
  final blockString = block.getSelection();
  var paramBlock = <String, String?>{
    'from': from?.asString,
    'to': address.asString,
    'gas': gas == null ? null : EthereumUtilities.intToHex(gas),
    'gasPrice':
        gasPrice == null ? null : EthereumUtilities.intToHex(gasPrice),
    'value': value == null ? null : EthereumUtilities.intToHex(value),
    'data': data?.asString
  };
  paramBlock =
      EthereumUtilities.removeNull(paramBlock) as Map<String, String?>;
  final dynamic params = <dynamic>[paramBlock, blockString];
  final dynamic res = await _client.rpcClient.request(method, params);
  if (res != null && res.containsKey(EthereumConstants.ethResultKey)) {
    return EthereumData.fromString(res[EthereumConstants.ethResultKey]);
  }
  _client.processError(method, res);
  return null;
}