smartcontractkit/full-blockchain-solidity-course-js

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')

barzoid1 opened this issue · 5 comments

Lesson

Lesson 5

Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")

No response

Operating System

None

Describe the bug

Hi thank you for helping me out. I installed garnache and set up everything pretty well but when i run my deploy.js i get the following error below. Attached below is my deploy.js code and the error i get

const ethers = require('ethers')
const fs = require('fs-extra')


async function main() {
    //https://127.0.0.1:7545
    const provider = new ethers.providers.JsonRpcProvider("https://127.0.0.1:7545");
    const wallet = new ethers.Wallet("0xa55af94d31c17fb6dcbe410267d774b528268293ebbcf44f71ca023e7911d9b6", provider);
    const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8")
    const binary = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin", "utf-8")
    const contractFactory = new ethers.ContractFactory(abi, binary, wallet)
    const contract = await contractFactory.deploy()
    console.log(contract)
}

main().then(() => process.exit(0)).catch((error) => {
    console.error(error);
    process.exit(1)
})
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')

i figured out the issue and solution.
i needed to downgrade to less than 0.6.0 version

how did you donwgraded to 0.6.0 version of ganache? been looking for a while but finded nothing.

@barzoid1
I read the documentation for it here: https://docs.ethers.org/v6/migrating/#migrate-providers

For version 6, providers were migrated to ethers.*

basically,
const provider = new ethers.providers.JsonRpcProvider("https://127.0.0.1:7545"); in version 5

is

const provider = new ethers.JsonRpcProvider("https://127.0.0.1:7545"); in version 6

I have tried both downgrading, which worked and the new migrated syntax which also worked.

solution explained in this ticket :

#6309 (comment)

change this :

new ethers.providers.JsonRpcProvider

to this

new ethers.JsonRpcProvider

how did you donwgraded to 0.6.0 version of ganache? been looking for a while but finded nothing.

you need to downgrade your ethers version to below 6... i ve install ethers with

npm i ethers@5.6.2