smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
11.94k stars 2.89k forks source link

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

Open barzoid1 opened 9 months ago

barzoid1 commented 9 months ago

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')
barzoid1 commented 9 months ago

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

Axel-C19 commented 8 months ago

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

ankitsinghtd commented 7 months ago

@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.

MehdiAbidri commented 7 months ago

solution explained in this ticket :

https://github.com/smartcontractkit/full-blockchain-solidity-course-js/issues/6309#issue-2014816029

change this :

new ethers.providers.JsonRpcProvider

to this

new ethers.JsonRpcProvider

bharathkumar369 commented 2 months ago

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