[Ethereum] “Nonce too low” using contract.methods.theFunction().send()

infuraweb3js

Using web3 to build a contract from the ABI:

contract = new web3.eth.Contract(JSON.parse(abi), '0x17c91A5a6f5e3E4BEaFC478D18C4A44D88833277', { from: '0x0Ad2b5CCe78D677fD000698a7E4Cde866DE189C6', gas: 100000})

contract.methods.myFunction('constructorVariable1', 'constructorVariable2').send()

First send completes successfully. Second+ send returns the error: nonce too low

  • Truffle v5.1.13 (core: 5.1.13)
  • Web3.js v1.2.1
  • Ropsten testnet
  • Infura as HDWalletProvider node

I can't find any documentation on manually increasing the nonce using the send() method. I would have also thought nonces would be increased automatically?

I should add that there were no pending transactions during these sends.

Update:

Disconnecting and reconnecting from truffle console resolved the issue.

Best Answer

I ran to the same nonce too low message. My issue was due to adding a wallet with a private key without the 0x prefix - simply adding the 0x prefix worked. Here is my working code:

let account = web3.eth.accounts.wallet.add("0x8f88c79e3.......");

TestContract.methods.testFunction().send({
    from: account.address,
    gas: '1000000',
    value: 0,
});

Related Topic