Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help me in deploy.js #6309

Open
Saad46469 opened this issue Nov 28, 2023 · 4 comments
Open

Help me in deploy.js #6309

Saad46469 opened this issue Nov 28, 2023 · 4 comments
Labels

Comments

@Saad46469
Copy link

Saad46469 commented Nov 28, 2023

I have done Everything according to the video but I'm still getting an error also my erroe is in deply.js lesson 5:
My code:

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

async function main() {
  // http://127.0.0.1:7545
  const provider = new ethers.providers.JsonRpcProvider(
    "HTTP://127.0.0.1:7545"
  );
  // need Private key and provider
  const Wallet = new ethers.Wallet(
    "0x558cc70107e27f955b18929f466564d6044269c09870c7e58ead521327ae0b12",
    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();
  });

My Error:

saad@DESKTOP-PREQOSC:~/BC/ether-simple-storage$ node deploy.js
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
    at main (/home/saad/BC/ether-simple-storage/deploy.js:6:41)
    at Object.<anonymous> (/home/saad/BC/ether-simple-storage/deploy.js:22:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
    ```
@ShawnFromTexas
Copy link

ShawnFromTexas commented Nov 30, 2023

I do not see a deply.js here?

Sounds like you need to check JsonRpcProvidor.

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

@Akshat162001
Copy link

My freind is also having this mistake so he tried some code that might solve your problem here is the solve it :
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 privateKey = "0x558cc70107e27f955b18929f466564d6044269c09870c7e58ead521327ae0b12";
const Wallet = new ethers.Wallet(privateKey, provider);

const abi = JSON.parse(fs.readFileSync("SimpleStorage_sol_SimpleStorage.abi", "utf8"));
const bytecode = "0x" + fs.readFileSync("SimpleStorage_sol_SimpleStorage.bin", "utf8");

const contractFactory = new ethers.ContractFactory(abi, bytecode, Wallet);

console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();
console.log("Contract address:", contract.address);
console.log("Transaction hash:", contract.deployTransaction.hash);

await contract.deployed();
console.log("Contract deployed successfully!");
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

@Akshat162001
Copy link

Hopefully it might work..

@MehdiAbidri
Copy link

remove providers object from the line below

so instead of :

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

write this :

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

this error maybe related to recent update which is not takken into account in this course.

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

No branches or pull requests

4 participants