11

I ran a hardhat node just fine using npx hardhat node, but after I shut it down and restarted it, whenever I try to deploy something on the chain, I get the following error:


eth_getTransactionCount

Received invalid block tag 87. Latest block number is 0

How to fix this?

zendevil.eth
  • 303
  • 1
  • 3
  • 10
  • use ganache :) until you find a solution for this error – Majd TL Sep 10 '21 at 14:20
  • ganache won't work ProviderError: Method hardhat_impersonateAccount not supported. #crying – Nat Sep 24 '21 at 15:39
  • made a gitub post https://github.com/nomiclabs/hardhat/issues/1906, there's an issue I included which may be related – Nat Sep 24 '21 at 15:52

4 Answers4

17

Try changing the network in Metamask and then switching back to the network you are using to connect to the hardhat node (probably the Localhost 8545 network).

There seems to be some sort of cache with the highest block number known, and it tries to keep using that value after the network is reset. This might be a Metamask issue, or maybe something in the dapp like the ethers.js provider.

Franco Victorio
  • 2,862
  • 17
  • 27
4

It seems metamask caches the current state of the blockchain, so when you restart the chain, it has incorrect data cached. There is a setting in metamask that lets you resync all this data:

Go to metamask > Settings > Advanced > Reset Account. This will clear the cache and reload data from the hardhat instance, and this error should go away.

0

I also got the same problem and I basically solved it by:

  1. Log in into MetaMask and choose the correct Localhost Network that was setup by you.
  2. Stop npx hardhat node
  3. When you have picked the correct account and network over metamask then try again with npx hardhat node

And then it worked for me. Hope that helped.

Fronin
  • 1
  • 2
0

In my case changing networks didn't help. I reinstalled Metamask and it fixed the problem

andr0-0
  • 47
  • 6