smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.01k stars 2.91k forks source link

Lesson 5: Cannot read properties of undefined (reading 'JsonRpcProvider') #5499

Closed LeeJianXing closed 1 year ago

LeeJianXing commented 1 year ago

Lesson

Lesson 5

Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")

https://youtu.be/gyMwXuJrbJQ?t=25647

Operating System

Windows

Describe the bug

I follow along with the tutorial, type the same code as instructor, but my code is not working.I want to run this code for see the contract object, but it cant.

Here is the 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"
      );
      const wallet = new ethers.Wallet(
        "0x915c3ab5eacdfd2c6ee2567a3712293922e3119f62889a4fc4e4d832462022f6",
        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);
      });
LeeJianXing commented 1 year ago

From Ganache go to setting -> hostname -> Select the one with (WSL), it works for me