I'm using web3js and web3js-raw as follows to change state of my smart contract on ethereum,
let initiateAddLoyaltyTransaction = function (fromWallet, toWallet, companyName, amount, callback) {
let functionName = 'transferWithAddLoyalty';
amount = web3.utils.toWei(amount.toString(), 'ether');
let params = [fromWallet, toWallet, amount, companyName];
W3JSR.prepareSignSend(config.ethereum[ethereumNetwork].ABI_DEFINITION, config.ethereum[ethereumNetwork].CONTRACT_ADDRESS, functionName,
config.ethereum[ethereumNetwork].WALLET_ADDRESS, privateKey, params, 10000000000).then((result, error) => {
callback(result, error);
});
};
It works fine when I call this function and wait for the transaction to mined by miners. But the problem is when I send another transaction before first one completes( because my use case needs to do several transactions in a short period of time) it gives an error saying
message: Error: Returned error: known transaction: 5abe27f97e23fb660b514c87c4d7db150dbd23bcf54632eef09fad6ec64427fe
I can see that the nonce is same for both transactions. Could someone please explain me how to deal with nonce while using Infura
. Do I need to maintain nonce localy? And how to retry if one transaction fails