estimateGas method

Future<BigInt> estimateGas({
  1. EthereumAddress? sender,
  2. EthereumAddress? to,
  3. EtherAmount? value,
  4. BigInt? gas,
  5. BigInt? gasPrice,
  6. BigInt? maxPriorityFeePerGas,
  7. BigInt? 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? gas,
  BigInt? gasPrice,
  BigInt? maxPriorityFeePerGas,
  BigInt? 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 (gas != null) 'gas': '0x${gas.toRadixString(16)}',
        if (gasPrice != null) 'gasPrice': '0x${gasPrice.toRadixString(16)}',
        if (maxPriorityFeePerGas != null)
          'maxPriorityFeePerGas':
              '0x${maxPriorityFeePerGas.toRadixString(16)}',
        if (maxFeePerGas != null)
          'maxFeePerGas': '0x${maxFeePerGas.toRadixString(16)}',
        if (value != null) 'value': '0x${value.getInWei.toRadixString(16)}',
        if (data != null) 'data': bytesToHex(data, include0x: true),
      },
    ],
  );
  return hexToInt(amountHex);
}