getFeeData method

Future<({BigInt maxFeePerGas, BigInt maxPriorityFeePerGas})> getFeeData([
  1. TransactionSpeed speed = TransactionSpeed.normal
])

Retrieves EIP-1559 fee parameters (maxFeePerGas and maxPriorityFeePerGas) from the network and returns a preset based on the requested TransactionSpeed.

This method queries the connected network via Web3Client.getGasInEIP1559, which typically returns three fee recommendations (slow, normal, fast). The preset returned corresponds to:

If no speed is provided, TransactionSpeed.normal is used.

Returns a record containing:

  • maxFeePerGas – the maximum total fee per unit of gas
  • maxPriorityFeePerGas – the miner tip per unit of gas

Example:

final fees = await getFeeData(TransactionSpeed.fast);
print('maxFee: ${fees.maxFeePerGas}, priority: ${fees.maxPriorityFeePerGas}');

See also:

Implementation

Future<({BigInt maxFeePerGas, BigInt maxPriorityFeePerGas})> getFeeData([
  TransactionSpeed speed = TransactionSpeed.normal,
]) async {
  final fee = await ctx.web3Client.getGasInEIP1559();
  return switch (speed) {
    TransactionSpeed.slow => (
      maxFeePerGas: fee[0].maxFeePerGas,
      maxPriorityFeePerGas: fee[0].maxPriorityFeePerGas,
    ),
    TransactionSpeed.normal => (
      maxFeePerGas: fee[1].maxFeePerGas,
      maxPriorityFeePerGas: fee[1].maxPriorityFeePerGas,
    ),
    TransactionSpeed.fast => (
      maxFeePerGas: fee[2].maxFeePerGas,
      maxPriorityFeePerGas: fee[2].maxPriorityFeePerGas,
    ),
  };
}