getGasCostEstimation<T> method

Future<int> getGasCostEstimation<T>(
  1. T tx, [
  2. String? signerAddress
])

Returns the estimated gas cost for the transaction, throw whens fails to estimate the gas cost.

Implementation

Future<int> getGasCostEstimation<T>(T tx, [String? signerAddress]) async {
  try {
    if (signerAddress == null || signerAddress.isEmpty) {
      getAddress(); // check signer address not null
    }
  } catch (e) {
    throw ArgumentError.notNull("signerAddress");
  }

  final txEffects = await dryRunTransaction(tx, signerAddress: signerAddress);
  if (txEffects.effects.status.status == ExecutionStatusType.failure) {
    throw ArgumentError(txEffects.effects.status.error);
  }
  final gasUsed = txEffects.effects.gasUsed;
  final gasEstimation = gasUsed.computationCost + gasUsed.storageCost;
  return gasEstimation;
}