Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

getting undefined error of JsonRpcProvider #76

Open
drleavio opened this issue Apr 21, 2023 · 6 comments
Open

getting undefined error of JsonRpcProvider #76

drleavio opened this issue Apr 21, 2023 · 6 comments

Comments

@drleavio
Copy link

const ethers = require("ethers");
const fs = require("fs-extra");

async function main() {
  //   HTTP://127.0.0.1:7545

  const provider = new ethers.provider.JsonRpcProvider("http://127.0.0.1:7545");

  const wallet = new ethers.Wallet(
    0x51196181b8c4d0748a3307769b92ae85522b3610e7fbb56c81d783437d21ef40,
    provider
  );
  const abi = fs.readFileSync("./SimpleStorage_sol_Storage.abi", "utf8");
  const binary = fs.readFileSync("./SimpleStorage_sol_Storage.bin", "utf8");
  const contractfactory = new ethers.ContractFactory(abi, binary, wallet);
  console.log("wait....contract is deploying");
  const contract = await contractfactory.deploy();
  console.log(contract);
}
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

@42maojin
Copy link

const { ethers, JsonRpcProvider } = require("ethers")
// and
const provider = new JsonRpcProvider("http://0.0.0.0:7545")

@drleavio
Copy link
Author

not working still giving the same error

@42maojin
Copy link

check ethers version, is the key,reason is version update

@roostiqcopilot
Copy link

const { ethers, JsonRpcProvider } = require("ethers") // and const provider = new JsonRpcProvider("http://0.0.0.0:7545")

@42maojin thanx, worked for me

@lalondelalonde
Copy link

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!

@Taruns123
Copy link

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/"
);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants