estimateGas method

Future<BigInt> estimateGas({
  1. EthereumAddress? sender,
  2. EthereumAddress? to,
  3. EtherAmount? value,
  4. BigInt? amountOfGas,
  5. EtherAmount? gasPrice,
  6. EtherAmount? maxPriorityFeePerGas,
  7. EtherAmount? maxFeePerGas,
  8. Uint8List? data,
  9. @Deprecated('Parameter is ignored') BlockNum? atBlock,
})

Estimate the amount of gas that would be necessary if the transaction was sent via sendTransaction. Note that the estimate may be significantly higher than the amount of gas actually used by the transaction.

Implementation

Future<BigInt> estimateGas({
  EthereumAddress? sender,
  EthereumAddress? to,
  EtherAmount? value,
  BigInt? amountOfGas,
  EtherAmount? gasPrice,
  EtherAmount? maxPriorityFeePerGas,
  EtherAmount? maxFeePerGas,
  Uint8List? data,
  @Deprecated('Parameter is ignored') BlockNum? atBlock,
}) async {
  final amountHex = await _makeRPCCall<String>(
    'eth_estimateGas',
    [
      {
        if (sender != null) 'from': sender.hex,
        if (to != null) 'to': to.hex,
        if (amountOfGas != null) 'gas': '0x${amountOfGas.toRadixString(16)}',
        if (gasPrice != null)
          'gasPrice': '0x${gasPrice.getInWei.toRadixString(16)}',
        if (maxPriorityFeePerGas != null)
          'maxPriorityFeePerGas':
              '0x${maxPriorityFeePerGas.getInWei.toRadixString(16)}',
        if (maxFeePerGas != null)
          'maxFeePerGas': '0x${maxFeePerGas.getInWei.toRadixString(16)}',
        if (value != null) 'value': '0x${value.getInWei.toRadixString(16)}',
        if (data != null) 'data': bytesToHex(data, include0x: true),
      },
    ],
  );
  return hexToInt(amountHex);
}