I am trying to deploy some contracts on Ropsten network. Here is my code
async function finalDeploy(r){
for(i=0; i<constructorParams.length; i++) {
const options = {
data: '0x' + myBin[r]+constructorParams[i],
gas: 5000000,
};
const signed = await web3.eth.accounts.signTransaction(options, privateKey1);
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction); // here error occured
console.log("Contract: " +r+" is deployed at " +receipt.contractAddress);
contractAddressess.push(receipt.contractAddress)
}
}
The above code is working perfectly on Ganache UI, but when i changed its provider from localhost to Web3.providers.HttpProvider("https://ropsten.infura.io/v3/7fb0bdc97cbe419...");
then i am receiving this error ;
UnhandledPromiseRejectionWarning: Error: Returned error: nonce too low
at Object.ErrorResponse (C:\Users\aa\node_modules\web3-core-helpers\src\errors.js:29:16)
at C:\Users\aa\node_modules\web3-core-requestmanager\src\index.js:140:36
at XMLHttpRequest.request.onreadystatechange (C:\Users\aa\node_modules\web3-providers-http\src\index.js:102:13)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1143:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:3816) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3816) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
try
/catch
block until success). – goodvibration Dec 24 '19 at 8:53