TypeError: Cannot read properties of undefined (reading “waitForTransaction”)
This post exists to help Solidity developers debug a very specific error for a project that uses hardhat.
My context: I was trying to run my test scripts.
The error “TypeError: Cannot read properties of undefined (reading “waitForTransaction”)” comes from mismatched versions of ethers.
ethers v6 introduced a new method called “waitForTransaction” on the transaction object
This error can appear when both ethers v6 and ethers v5 are jumbled up.
In my case, I already had ethers 6.7.1 as a direct dependency
My error’s stack trace mentioned the package “@nomicfoundation/hardhat-chai-matchers”
I noticed that it was on v1 while the latest version is v2.
I updated that to v2, then I faced a different error, complaining again about a missing property/method. This time, it was “TypeError: Cannot read properties of undefined (reading ‘JsonRpcProvider’)”
At this moment I realised that I had both “@nomicfoundation/hardhat-ethers” and “@nomiclabs/hardhat-ethers” installed. I realised that the nomiclabs hardhat-ethers version was 2.2.3 while the nomicfoundation hardhat-ethers version was 3.0.4
FYI, Nomic Labs became Nomic Foundations.
I removed the “@nomiclabs/hardhat-ethers”.