Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Resolving Error: TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') when try do deploy #88

Open
Maximesol opened this issue Jun 23, 2023 · 2 comments

Comments

@Maximesol
Copy link

Maximesol commented Jun 23, 2023

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 :

const ethers = require("ethers");

const provider = new ethers.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");

const provider = new JsonRpcProvider("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.

@vulpes231
Copy link

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.

@ArtemYo8283
Copy link

ArtemYo8283 commented Nov 22, 2023

you can also use

const provider = new ethers.JsonRpcProvider("address of your local ganache BC");

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants