You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 17, 2024. It is now read-only.
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 :
constethers=require("ethers");constprovider=newethers.providers.JsonRpcProvider("address of your local ganache BC");
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:
const{ ethers, JsonRpcProvider }=require("ethers");constprovider=newJsonRpcProvider("address of your local ganache BC");
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.
The text was updated successfully, but these errors were encountered:
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.
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.
The text was updated successfully, but these errors were encountered: