36

I have been experimenting with truffle recently and followed the following tutorial: http://truffleframework.com/tutorials/pet-shop

Whenever I try to setup a transaction I keep getting the same error below

Error: Error: the tx doesn't have the correct nonce. account has nonce of: 14 tx has nonce of: 0

Checked online and read up on a lot of articles related to this but so far haven't found what might be causing this issue.

  • Truffle v3.4.7
  • Solidity v0.4.13
  • Npm v5.3.0
  • TestRPC v4.0.1 (also happen with Ganache)
  • Metamask v3.9.5

From what I understand it seems it is unable to find the previous transactions to hash the new transaction?

Muhammad Altabba
  • 2,583
  • 19
  • 31
user1664
  • 481
  • 1
  • 7
  • 6

3 Answers3

43

Using MetaMask v3.14.1 you can reset your account as follow:

Resetting an Account In the Settings menu, MetaMask has a "Reset Account" button. This button wipes the current account's transaction history, which is used to calculate the current account nonce.

enter image description here

Normal users should never have a reason to use this feature.

This is useful for developers who reset a test network but want to continue using the same account, forcing MetaMask to believe this network ID is a clean network in a fresh state.

Ref: http://metamask.helpscoutdocs.com/article/36-resetting-an-account

(Thanks to Tim Wu)


Old response: Answer of yatskevich is correct.

However, for people how are using Truffle 4+ with "truffle develop", you need to remove and reinstall MetaMask to get it work again, every time you run Truffle Develop!

This issue is addressed here: https://github.com/trufflesuite/truffle/issues/681, here: https://github.com/trufflesuite/ganache/issues/112, and also here: https://github.com/MetaMask/metamask-extension/issues/1999

In short they are working on it and in the mean time you need to reinstall MetaMask every time!

Community
  • 1
  • 1
Muhammad Altabba
  • 2,583
  • 19
  • 31
  • 1
    the metamask issue will soon be solved https://github.com/MetaMask/metamask-extension/issues/1999#issuecomment-347615959 and truffle is now waiting for their fix https://github.com/trufflesuite/trufflesuite.com/issues/30#issuecomment-348573629 – jopasserat Dec 09 '17 at 12:40
  • 1
    Note that you can also simple disable and then re-enable metamask. Still a pain, but not quite as bad as re-installing. I also made a patch for truffle develop that can be a short term fix: https://github.com/MetaMask/metamask-extension/issues/1999#issuecomment-354141687 – Stan James Jan 06 '18 at 19:06
  • 1
    @StanJames Note, using this fix messes up Event firing, for some reason events did not fire after changing the network_id. – Random Jan 13 '18 at 12:56
  • I am using Ganache and MetaMask. Removing then reinstalling MetaMask works :) What a pain... – Russo Jan 16 '18 at 10:17
  • Metamask's author released a workaround this issue in v3.14.1. I tried it. It works. https://github.com/MetaMask/metamask-extension/issues/1999#issuecomment-362445864 – Tim Wu Feb 12 '18 at 02:16
  • 1
    thanks. this worked. maybe it got reintroduced? I'm running MM v4.6.1 with truffle v4.1.6 and I just got it(after days of the same app/transactions working fine) – Ioana Grozav May 16 '18 at 07:46
30

Try to reconnect to your TestRPC network in MetaMask:

  1. Select Main Ethereum Network (or any other than Localhost 8545)
  2. Select Localhost 8545 again

I've stumbled upon this issue after stopping and starting a new TestRPC node.

yatskevich
  • 2,085
  • 16
  • 25
3

Check your truffle.js or truffle-config.js

if you are using the HDWalletProvider like below, it seems that this is what causing the error

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "your mnemonic";

module.exports = {
  networks: {
    development: {
      provider: function() {
        return new HDWalletProvider(mnemonic, "http://127.0.0.1:8545/", 0, 50);
      },
      network_id: '*',
      gas: 9999999
    }
  },
  compilers: {
    solc: {
      version: "^0.4.25"
    }
  }
};

remove the HDWalletProvider like below, it solves mine

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost
      port: 8545,            // Standard Ganache UI port
      network_id: "*", 
      gas: 4600000
    }
  },
  compilers: {
    solc: {
      version: "0.5.2"
    }
  }
};
grandia
  • 709
  • 7
  • 20