getFeeData method
Future<({BigInt maxFeePerGas, BigInt maxPriorityFeePerGas})>
getFeeData([
- 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 gasmaxPriorityFeePerGas– the miner tip per unit of gas
Example:
final fees = await getFeeData(TransactionSpeed.fast);
print('maxFee: ${fees.maxFeePerGas}, priority: ${fees.maxPriorityFeePerGas}');
See also:
- TransactionSpeed – preset selection for fee biasing.
- https://eips.ethereum.org/EIPS/eip-1559
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,
),
};
}