estimateGasLimit method
Estimate Gas Fee
Implementation
Future<BigInt> estimateGasLimit({
String? from,
required String to,
BigInt? amount,
BigInt? gasPrice,
String? data,
}) async {
try {
final response = await _call<String>(
'eth_estimateGas',
args: [
{
if (from != null) 'from': from,
'to': to,
if (gasPrice != null) 'gasPrice': gasPrice.toHexWithPrefix,
if (data != null) 'data': data,
if (amount != null) 'value': amount.toHexWithPrefix,
}
],
);
final gasFee = response.toBigIntOrNull;
if (gasFee == null) throw Exception('Could not parse gas fee');
return gasFee;
} catch (e) {
Logger.logError(
e,
hint: 'estimateGasLimit failed - falling back to hardcoded gasLimit',
);
return BigInt.from(95000);
}
}