<No solution works!> TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') #4745
-
Hey guys, I bumped into this issue when following this video at 7:07:00, and I tried all solutions from similar post but none worked so far. I got this error message when running My code for this file is as follows: const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
// compile separately
// http://127.0.0.1:7545
// console.log(ethers.provider.JsonRpcProvider); // this produce the same error
const provider = new ethers.provider.JsonRpcProvider(
"http://172.22.48.1:7545" // after setting vEthernet (WSL) in Ganache Win11
);
console.log("here");
const wallet = new ethers.Wallet(
"cabfa4caf52f1cb467a3898e748d1b06852efeca71fa41a048a25caf4a5bc813", // private key copied from Ganache
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();
console.log(contract);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); My package.json is as follows: {
"dependencies": {
"ethers": "5.7.2",
"fs-extra": "^11.1.0",
"ganache": "^7.7.4",
"solc": "0.8.7-fixed"
},
"scripts": {
"compile": "yarn solcjs --bin --abi --include-path node_modules/ --bath-path . -o . SimpleStorage.sol"
}
} Any suggestions would be much appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Feb 6, 2023
Replies: 1 comment 3 replies
-
@lqpchen It is |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
lqpchen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lqpchen It is
ethers.providers
notprovider