getEthereumBaseFee method

Future<BigRational?> getEthereumBaseFee({
  1. Duration? timeout,
})

Implementation

Future<BigRational?> getEthereumBaseFee({Duration? timeout}) async {
  BigRational parseFee(String? baseFee) {
    if (baseFee == null) {
      throw RPCError(
        message: "Unexpected service response. missing base fee.",
      );
    }
    final fee = BigInt.tryParse(baseFee);
    if (fee != null) return BigRational(fee);
    return BigRational(AmountConverter.eth.toUnit(baseFee));
  }

  try {
    final result = await query(
      const etheremint.QueryBaseFeeRequest(),
      timeout: timeout,
    );
    return parseFee(result.baseFee);
  } on RPCError catch (e) {
    if (CosmosProviderUtils.notImplemented(e.errorCode)) {
      try {
        final result = await query(const cosmos_evm.QueryBaseFeeRequest());

        return parseFee(result.baseFee);
      } on RPCError catch (e) {
        if (CosmosProviderUtils.notImplemented(e.errorCode)) return null;
        rethrow;
      }
    }
    rethrow;
  }
}