TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') #5252
-
I'm having difficulty figuring out why the JsonRpcProvider is not working properly, I've had a look around and most answers i've read suggest to downgrade the ethers js version to 5.7. i'm currently using 6.2 const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:7545");
const wallet = new ethers.Wallet("0xb112e3303c9e9c9b61fc2627787704424c2d399a63b3d2e4853c7bd7701ea749", provider);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const binary = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin", "utf8");
const contractFactory = new ethers.contractFactory(abi, binary, wallet);
console.log("deploying.. please wait..");
const contract = await contractFactory.deploy(); // stop here, wait for contract to finish
console.log(contract);
}
main().then(() => process.exit(0)).catch((error)=> console.log(error)); is there another way to get this working without downgrading? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
@ejmorian Yes, the latest version syntax is like this |
Beta Was this translation helpful? Give feedback.
-
install web3 it will fix it |
Beta Was this translation helpful? Give feedback.
@ejmorian Yes, the latest version syntax is like this
ethers.JsonRpcProvider
, but I would still recommend using a version below 6. Because from lesson 6 you will be using hardhat-deploy dependency which is not updated to version 6 and ethers version 6 is still in beta.