estimateGas method
Estimate gas Makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas. See eth_call parameters, expect that all properties are optional. If no gas limit is specified geth uses the block gas limit from the pending block as an upper bound. As a result the returned estimate might not be enough to executed the call/transaction when the amount of gas is higher than the pending block gas limit. Returns the amount of gas used.
Implementation
Future<int> estimateGas(
{BigInt address,
BigInt from,
int gas,
int gasPrice,
int value,
BigInt data}) async {
Map<String, String> paramBlock = {
"from": from == null ? null : MoacUtilities.bigIntegerToHex(from),
"to": address == null ? null : MoacUtilities.bigIntegerToHex(address),
"gas": gas == null ? null : MoacUtilities.intToHex(gas),
"gasPrice": gasPrice == null ? null : MoacUtilities.intToHex(gasPrice),
"value": value == null ? null : MoacUtilities.intToHex(value),
"data": data == null ? null : MoacUtilities.bigIntegerToHex(data)
};
paramBlock = MoacUtilities.removeNull(paramBlock);
final dynamic params = [paramBlock];
final String method = MoacRpcMethods.estimateGas;
final res = await rpcClient.request(method, params);
if (res != null && res.containsKey(moacResultKey)) {
return MoacUtilities.hexToInt(res[moacResultKey]);
}
_processError(method, res);
return null;
}