From b6981b20075b233f3429ac15564e90739c169155 Mon Sep 17 00:00:00 2001 From: Victor Vicente Date: Tue, 2 Oct 2018 09:41:53 -0300 Subject: [PATCH] CLI: Gas limit for estimation --- CLI/commands/common/common_functions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CLI/commands/common/common_functions.js b/CLI/commands/common/common_functions.js index 07de69fec..dbf3aa8dd 100644 --- a/CLI/commands/common/common_functions.js +++ b/CLI/commands/common/common_functions.js @@ -50,7 +50,12 @@ module.exports = { sendTransaction: async function (from, action, gasPrice, value, factor) { if (typeof factor === 'undefined') factor = 1.2; + let block = await web3.eth.getBlock("latest"); + let networkGasLimit = block.gasLimit; + let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value}))); + if (gas > networkGasLimit) gas = networkGasLimit; + console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gas} ----`)); let nonce = await web3.eth.getTransactionCount(from.address);