getGasCostEstimation<T> method
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;
}