Skip to content
27 changes: 18 additions & 9 deletions CLI/commands/common/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = {
`);
},
getNonce: async function(from) {
return (await web3.eth.getTransactionCount(from.address));
return (await web3.eth.getTransactionCount(from.address, "pending"));
},
sendTransaction: async function (from, action, gasPrice, value, factor) {
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);
Expand All @@ -94,8 +94,12 @@ module.exports = {
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;
try {
let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
if (gas > networkGasLimit) gas = networkGasLimit;
} catch(exception) {
gas = networkGasLimit;
}

console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gas} ----`));

Expand Down Expand Up @@ -129,7 +133,7 @@ module.exports = {
);
});
},
sendTransactionWithNonce: async function (from, action, gasPrice, value, factor, minNonce) {
sendTransactionWithNonce: async function (from, action, gasPrice, minNonce, value, factor) {
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);

//NOTE this is a condition to verify if the transaction comes from a module or not.
Expand All @@ -143,16 +147,21 @@ module.exports = {
process.exit(0);
}
}
if (typeof factor === 'undefined') factor = 1.2;
let block = await web3.eth.getBlock("latest");
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})));

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);
if (nonce < minNonce)

let nonce = await web3.eth.getTransactionCount(from.address);

if (nonce < minNonce) {
nonce = minNonce;
}
let abi = action.encodeABI();
let parameter = {
from: from.address,
Expand Down
4 changes: 2 additions & 2 deletions CLI/commands/common/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function getGasPrice (networkId) {
let gasPrice;
switch (networkId) {
case 1: //Mainnet
gasPrice = 30000000000;
gasPrice = 20000000000;
break;
case 3: //Ropsten
gasPrice = 50000000000;
Expand All @@ -13,7 +13,7 @@ function getGasPrice (networkId) {
gasPrice = 50000000000;
break;
case 42: //Kovan
gasPrice = 50000000000;
gasPrice = 5000000000;
break;
default:
throw new Error('Network ID not identified');
Expand Down
Loading