getFeeHistory method

Future<FeeHistory> getFeeHistory(
  1. int blockCount, {
  2. BlockNum? atBlock,
  3. List<double>? rewardPercentiles,
})

Returns fee history of some blocks

Implementation

Future<FeeHistory> getFeeHistory(
  int blockCount, {
  BlockNum? atBlock,
  List<double>? rewardPercentiles,
}) async {
  final blockParam = _getBlockParam(atBlock);
  final history = await _makeRPCCall<Map<String, dynamic>>(
    'eth_feeHistory',
    [blockCount, blockParam, rewardPercentiles],
  );
  final oldestBlock = BigInt.parse(history['oldestBlock'] as String);
  final baseFeePerGas = List<String>.from(history['baseFeePerGas'])
      .map((e) => BigInt.parse(e))
      .toList();
  final reward = history['reward'] != null
      ? List.from(history['reward'])
          .map((dynamic e) => List<String>.from(e))
          .map(
            (e) => e
                .map(
                  (e) => BigInt.parse(e),
                )
                .toList(),
          )
          .toList()
      : null;

  final gasUsedRatio = List<num>.from(history['gasUsedRatio'])
      .map((e) => e.toDouble())
      .toList();

  return FeeHistory(
    baseFeePerGas,
    oldestBlock,
    gasUsedRatio,
    reward,
  );
}