smartcontractkit / full-blockchain-solidity-course-js

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

My code is #6548

Open Waseem-Baig opened 2 months ago

Waseem-Baig commented 2 months ago

My code is

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

async function main() {
  const provider = new ethers.JsonRpcProvider("http://127.0.0.1:7545");
  const wallet = new ethers.Wallet(
    "0x599abf72bfd352de8cbf0d4bed61a061aa9e8de956b283642aa8e1f75b33766f",
    provider
  );
  const abi = fs.readFileSync(
    "SimpleStorage_sol_SimpleStorage.abi",
    "utf-8"
  );
  const binary = fs.readFileSync(
    "SimpleStorage_sol_SimpleStorage.abi",
    "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.error(error);
    process.exit();
  });

Error is

TypeError: invalid BytesLike value (argument="value", value="0x[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_name\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"_favoriteNumber\",\"type\":\"uint256\"}],\"name\":\"addPerson\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"name\":\"nameToFavoriteNumber\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"people\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"favoriteNumber\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"retrieve\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_favoriteNumber\",\"type\":\"uint256\"}],\"name\":\"store\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", code=INVALID_ARGUMENT, version=6.11.1)
    at makeError (D:\Web3\hh-fcc\ethers-simple-storage-fcc\node_modules\ethers\lib.commonjs\utils\errors.js:122:21)
    at assert (D:\Web3\hh-fcc\ethers-simple-storage-fcc\node_modules\ethers\lib.commonjs\utils\errors.js:149:15)
    at assertArgument (D:\Web3\hh-fcc\ethers-simple-storage-fcc\node_modules\ethers\lib.commonjs\utils\errors.js:161:5)
    at _getBytes (D:\Web3\hh-fcc\ethers-simple-storage-fcc\node_modules\ethers\lib.commonjs\utils\data.js:27:36)
    at getBytes (D:\Web3\hh-fcc\ethers-simple-storage-fcc\node_modules\ethers\lib.commonjs\utils\data.js:37:12)
    at new ContractFactory (D:\Web3\hh-fcc\ethers-simple-storage-fcc\node_modules\ethers\lib.commonjs\contract\factory.js:46:72)
    at main (D:\Web3\hh-fcc\ethers-simple-storage-fcc\deploy.js:18:27)
    at Object.<anonymous> (D:\Web3\hh-fcc\ethers-simple-storage-fcc\deploy.js:24:1)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10) {code: 'INVALID_ARGUMENT', argument: 'value', value: '0x[{"inputs":[{"internalType":"string","name"…eMutability":"nonpayable","type":"function"}]', shortMessage: 'invalid BytesLike value', stack: 'TypeError: invalid BytesLike value (argument=…js (node:internal/modules/cjs/loader:1427:10)', …}

Originally posted by @Waseem-Baig in https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/6547