estimateGas method

  1. @override
Future<BigInt> estimateGas(
  1. EthereumAddress to,
  2. String calldata
)

Asynchronously estimates the gas cost for a transaction to the specified address with the given calldata.

Parameters:

  • to: The EthereumAddress of the transaction recipient.
  • calldata: The ABI-encoded data for the transaction.

Returns: A Future that completes with a BigInt representing the estimated gas cost.

Example:

var gasEstimation = await estimateGas(
  EthereumAddress.fromHex('0x9876543210abcdef9876543210abcdef98765432'),
  '0x0123456789abcdef',
);

This method uses an ethereum jsonRPC to estimate the gas cost for the specified transaction.

Implementation

@override
Future<BigInt> estimateGas(EthereumAddress to, String calldata) {
  return rpc.send<String>('eth_estimateGas', [
    {'to': to.hex, 'data': calldata}
  ]).then(hexToInt);
}