trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.32k forks source link

Truffle develop static network id interferes with MetaMask #681

Closed pimotte closed 6 years ago

pimotte commented 6 years ago

Issue

When using truffle develop a constant network id is used. When shutting down a truffle develop session, the transactions in the testrpc will disappear, but MetaMask will remember them. This will result in errors of the form: 'Error: tx doesn't have the correct nonce'. The corresponding MetaMask issue is here: https://github.com/MetaMask/metamask-extension/issues/1999

Unless there is a good reason to have the static network id, I feel it would be really useful to signal that the blockchain in question is a different blockchain, by virtue of it having a different network id (and possibly chain id).

Steps to Reproduce

  1. Unbox and start the react box using truffle develop.
  2. Open localhost:3000 and Accept the transaction
  3. Close truffle develop (make sure the process has stopped)
  4. Run truffle develop, compile, migrate.
  5. Open localhost:3000 and Accept transaction

Expected Behavior

The transaction in step 5 succeeds, by virtue of no prior transactions being in MetaMask, because the second truffle develop generated a new network id.

Actual Results

The transaction in step 5 fails, due to 'Error: tx doesn't have the correct nonce'

Environment

rheaplex commented 6 years ago

Importing fresh seeds fills up Metamask with old addresses in my experience.

IMO it would be better for this to be fixed by Metamask as part of their nonce handling improvements.

pimotte commented 6 years ago

What do you mean with that first sentence? Reimporting the seed is a workaround?

In any case, the metamask issue says they are not looking to bend over backwards to detect differences between private networks. Doesn't it make sense to use a new network or chain id when you're starting from scratch?

rheaplex commented 6 years ago

I tried it and importing a new seed doesn't work now. :-(

I just tried with a new network ID in Ganache and that doesn't work either.

Between testrpc and Ganache not working with Metamask without a complete reinstall, and failing in Mist with "Account not found" when trying to send transactions I'm not sure what to use to test UI.

pimotte commented 6 years ago

The MetaMask issue speaks of an undocumented chainId option in testrpc. Can we use that in Ganache to force MetaMask to re-read the transactions?

I'm of the opinion that this is actually an issue on both sides (i.e. truffle develop should be using random id's, unless pinned by an argument, and metamask should be caching less aggressively)

tcoulter commented 6 years ago

Hi all.

Metamask is currently trying to fix this on their end. Bug here: https://github.com/MetaMask/metamask-extension/issues/1999

We believe their fix should be all that's needed. I'm going to close this ticket in favor of theirs. Cheers!

wanderingstan commented 6 years ago

Metamask has postponed fixing this on their end: https://github.com/MetaMask/metamask-extension/issues/1999#issuecomment-354012719

There is a "patch" that may allow you to continue to use truffle develop in the meantime: https://github.com/MetaMask/metamask-extension/issues/1999#issuecomment-354141687