3

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?

1 Answer 1

5

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.

1
  • I had a similar error: TypeError: Cannot read properties of undefined (reading 'sourceName'). This was thrown when calling loadFixture on the same fixture that worked in other tests, and the test itself worked when ran individually but not when ran as part of the suite. This update command fixed it.
    – Origin
    Commented Jul 8, 2023 at 23:15

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.