estimateFeeForPriority function

Future<Amount> estimateFeeForPriority({
  1. required int blocks,
  2. required UTXONetworkType network,
  3. required ElectrumXClient? initalClient,
})

Implementation

Future<Amount> estimateFeeForPriority({
  required int blocks,
  required UTXONetworkType network,
  required ElectrumXClient? initalClient,
}) async {
  final (fee, _, _) = await fetchFromRandomElectrumXNode(
    (client) => client.estimateFee(blocks: blocks),
    client: initalClient,
    endpoints: network.endpoints,
    token: network.coin,
  );

  if (fee == null) throw Exception("Fee estimation failed");

  final feePerKb = Amount.convert(value: fee, decimals: 8);

  final feePerB = feePerKb / Amount.from(value: 1000, decimals: 0);

  return feePerB;
}