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:


  Received invalid block tag 87. Latest block number is 0

How to fix this?

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

4 Answers 4


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.


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.

  • Looks like metamask no longer have Reset Account option . It is rather Clear Activity Tab Data. I did try it no effect the error remains...
    – sandy_1111
    May 16 at 10:20

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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.