Open drleavio opened 1 year ago
const { ethers, JsonRpcProvider } = require("ethers") // and const provider = new JsonRpcProvider("http://0.0.0.0:7545")
not working still giving the same error
check ethers version, is the key,reason is version update
const { ethers, JsonRpcProvider } = require("ethers") // and const provider = new JsonRpcProvider("http://0.0.0.0:7545")
@42maojin thanx, worked for me
Hey guys, I'll copy-paste an answer I gave, I was stuck on the same problem.
const { ethers } = require("ethers"); const fs = require("fs");
async function main() { const provider = new ethers.providers.JsonRpcProvider( "http://127.0.0.1:7545/" ); const wallet = new ethers.Wallet( "0xb357c12e59c02b0b6bde61434adda8ab38a29f2db7bb109ec360955b55404677", provider ); const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8"); const bin = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.bin", "utf8"); const contractFactory = new ethers.ContractFactory(abi, bin, wallet); console.log("Deploying, please wait..."); const contract = await contractFactory.deploy(); // Stop here and wait for the contract to deploy const deploymentReceipt = await contract.deployTransaction.wait(1); console.log(deploymentReceipt); }
main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); });
I unistalled the node_modules and reinstalled it. Also I'm using Ethers 5.6.2 and modify a little bit of the code listening to some this and input from ChatGPT. Good luck bro!
what i got to know in the later versions the file structure was more well defined so as to put the jsonRpcProvider in the providers , but in the earlier section the JsonRpcProvider was in the ethers itself
you can try this instead
const provider = new ethers.JsonRpcProvider(
"http://127.0.0.1:7545/"
);