With the function estimate_transaction_cost(tolerance: Option<f64>) provided by ContractCallHandler and ContractMultiCallHandler, you can get a cost estimation for a specific call. The return type, TransactionCost, is a struct that contains relevant information for the estimation:
TransactionCost { min_gas_price:u64, min_byte_price:u64, gas_price:u64, gas_used:u64, metered_bytes_size:u64, total_fee:f64, // where total_fee is the sum of the gas and byte fees}
Below are examples that show how to get the estimated transaction cost from single and multi call transactions.
let contract_instance =MyContract::new(contract_id, wallet);let tolerance =0.0;let transaction_cost = contract_instance.methods().initialize_counter(42) // Build the ABI call.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost.await?;