Hardhat – Fixing ‘Cannot Read Properties of Undefined (reading ‘gteHardfork’)’ When Deploying Contract

hardhathardhat-deploy

I'm following this tutorial – https://www.freecodecamp.org/news/solidity-tutorial-hardhat-nfts/
but when running

npx hardhat test

or

npx hardhat run scripts/deploy.js

I'm getting the following error:

TypeError: Cannot read properties of undefined (reading 'gteHardfork')
      at new Transaction (node_modules\@ethereumjs\tx\src\legacyTransaction.ts:111:21)
      at new FakeSenderTransaction (node_modules\hardhat\src\internal\hardhat-network\provider\transactions\FakeSenderTransaction.ts:92:5)
      at HardhatNode._getFakeTransaction (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:1118:12)
      at HardhatNode.estimateGas (node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:506:27)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:526:9)
      at processTimers (node:internal/timers:500:7)
      at EthModule._estimateGasAction (node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:421:9)
      at HardhatNetworkProvider.request (node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:99:18)

When I tried the same commands on the repo referenced in the article, everything worked fine there.
I've tried matching all the dependency versions and compared my whole project to it, but problem didn't go away.

What can be the reason?

Best Answer

Upgrading hardhat should fix your problem:

npm i --save-dev hardhat@latest

The reason why this happened is that there are some compatibility issues between older versions of hardhat and newer versions of ethereumjs (the EVM implementation used by Hardhat under the hood).

And the reason the command worked fine in the example repo but not when you executed the commands is that the repo has a package-lock.json file which probably has compatible versions of ethereumjs.

Related Topic