Open Maximesol opened 1 year ago
I encountered the same problem, and after searching online, I discovered that the solution was to execute the following command in the command line: npm install ethers@^5.7.2.
This command effectively downgraded the ethers library to version 5.7.2, which also resolved the issue for me.
you can also use
const provider = new ethers.JsonRpcProvider("address of your local ganache BC");
Problem :
When I was trying to use the ethers module in my Solidity project to interact with my contract deployed on Ganache, I encountered an error: TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider').
My code looked like this, like in the course :
Error Resolution : I realized that the error was due to how I was importing and using the ethers module. In the original code, I imported the entire ethers module and assigned it to the constant ethers. However, when I tried to access JsonRpcProvider with ethers.providers.JsonRpcProvider, it wasn't found because it doesn't exist at that location in the ethers module's structure.
To resolve the error, I used a JavaScript feature called destructuring assignment to extract ethers and JsonRpcProvider directly from the ethers module. Here's what the corrected code looks like:
This worked and my contract was successfully deployed on Ganache. I hope this can help someone else who encounters the same error. I'm a newbie so if I've said something stupid don't hesitate to correct me.