Skip to content

Commit c5fe850

Browse files
authored
Merge pull request #406 from PolymathNetwork/nonce-fix
[WIP] Nonce fix
2 parents ebec962 + 5650ed8 commit c5fe850

File tree

4 files changed

+139
-92
lines changed

4 files changed

+139
-92
lines changed

CLI/commands/common/common_functions.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
`);
7373
},
7474
getNonce: async function(from) {
75-
return (await web3.eth.getTransactionCount(from.address));
75+
return (await web3.eth.getTransactionCount(from.address, "pending"));
7676
},
7777
sendTransaction: async function (from, action, gasPrice, value, factor) {
7878
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);
@@ -94,8 +94,12 @@ module.exports = {
9494
let block = await web3.eth.getBlock("latest");
9595
let networkGasLimit = block.gasLimit;
9696

97-
let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
98-
if (gas > networkGasLimit) gas = networkGasLimit;
97+
try {
98+
let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
99+
if (gas > networkGasLimit) gas = networkGasLimit;
100+
} catch(exception) {
101+
gas = networkGasLimit;
102+
}
99103

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

@@ -129,7 +133,7 @@ module.exports = {
129133
);
130134
});
131135
},
132-
sendTransactionWithNonce: async function (from, action, gasPrice, value, factor, minNonce) {
136+
sendTransactionWithNonce: async function (from, action, gasPrice, minNonce, value, factor) {
133137
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);
134138

135139
//NOTE this is a condition to verify if the transaction comes from a module or not.
@@ -143,16 +147,21 @@ module.exports = {
143147
process.exit(0);
144148
}
145149
}
146-
if (typeof factor === 'undefined') factor = 1.2;
147-
let block = await web3.eth.getBlock("latest");
150+
if (typeof factor === 'undefined') factor = 1.2;
151+
152+
let block = await web3.eth.getBlock("latest");
148153
let networkGasLimit = block.gasLimit;
149-
let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
154+
155+
let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
150156
if (gas > networkGasLimit) gas = networkGasLimit;
151157

152158
console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gas} ----`));
153-
let nonce = await web3.eth.getTransactionCount(from.address);
154-
if (nonce < minNonce)
159+
160+
let nonce = await web3.eth.getTransactionCount(from.address);
161+
162+
if (nonce < minNonce) {
155163
nonce = minNonce;
164+
}
156165
let abi = action.encodeABI();
157166
let parameter = {
158167
from: from.address,

CLI/commands/common/global.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function getGasPrice (networkId) {
44
let gasPrice;
55
switch (networkId) {
66
case 1: //Mainnet
7-
gasPrice = 30000000000;
7+
gasPrice = 20000000000;
88
break;
99
case 3: //Ropsten
1010
gasPrice = 50000000000;
@@ -13,7 +13,7 @@ function getGasPrice (networkId) {
1313
gasPrice = 50000000000;
1414
break;
1515
case 42: //Kovan
16-
gasPrice = 50000000000;
16+
gasPrice = 5000000000;
1717
break;
1818
default:
1919
throw new Error('Network ID not identified');

0 commit comments

Comments
 (0)