smartcontractkit / full-blockchain-solidity-course-js

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

TypeError: invalid BytesLike value #4739

Closed mikakort closed 1 year ago

mikakort 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://www.youtube.com/watch?v=gyMwXuJrbJQ&t=25657s

Operating System

Windows

Describe the bug

Error given:

TypeError: invalid BytesLike value (argument="value", value="45286e1622b10ca3d0aa7031bc97f67d85e9d13572b57423487c2eea964d74f1", code=INVALID_ARGUMENT, version=6.0.2)

deploy.js:

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

async function main() {
  const provider = new ethers.JsonRpcProvider("http://0.0.0.0:7545");
  const wallet = new ethers.Wallet(
    "45286e1622b10ca3d0aa7031bc97f67d85e9d13572b57423487c2eea964d74f1",
    provider
  );
  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8");
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf-8"
  );

  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.log(error);
    process.exit(1);
  `});
mikakort commented 1 year ago

I fixed it by:

  1. writing this command in the terminal: yarn add ethers@5.7.2 (turns out there's an issue with 6.0.0+ versions of etherjs)

  2. changing my code from: const provider = new ethers.JsonRpcProvider("http://0.0.0.0:7545"); TO: const provider = new ethers.providers.JsonRpcProvider( "HTTP://172.25.0.1:7545");

  3. changing the ganache server connection to: vEthernet(WSL) (to change the connection, click on the settings button on the right of the screen, click on SERVER and choose the connection type with (WSL) in the name)

Kunsect commented 1 year ago

add 0x before "45286e1622b10ca3d0aa7031bc97f67d85e9d13572b57423487c2eea964d74f1"

PS2307 commented 1 year ago

Thanks dude @MrPimpDaddy69420