Error: cannot estimate gas; transaction may fail or may require manual gas limit SERVER_ERROR

53 views Asked by At

I am trying to deploy a SimpleStorage solidity contract using javascript on WSL studio and Ganache.

My deploy.js code is:

const ethers = require("ethers");
const { readFileSync } = require("fs");
const fs = require("fs-extra");
async function main() {
  //
  const provider = new ethers.providers.JsonRpcProvider(
    "http://172.24.176.1:7545"
  );
  const wallet = new ethers.Wallet(
    "0x757b08fac160cc001a4adfebadc26ac10a6e59e2490fda35bce0c35939f265f1",
    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(); //STOP here wait for contract to deploy
  console.log(contract);
}

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

I tried the command "node deploy.js" on the terminal and I got the following error:

root@LAPTOP-UFP1511I:~/folder/hh-fcc/ethers-simple-storage-fcc# node deploy.js Deploying, please wait...

<ref *1> Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{"id":49,"jsonrpc":"2.0","error":{"message":"VM Exception while processing transaction: invalid opcode","stack":"RuntimeError: VM Exception while processing transaction: invalid opcode\n at exactimate (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:182136)","code":-32000,"name":"RuntimeError","data":{"hash":null,"programCounter":24,"result":"0x","reason":null,"message":"invalid opcode"}}}","error":{"code":-32000,"data":{"hash":null,"programCounter":24,"result":"0x","reason":null,"message":"invalid opcode"}},"requestBody":"{"method":"eth_estimateGas","params":[{"type":"0x2","maxFeePerGas":"0xd09dc300","maxPriorityFeePerGas":"0x59682f00","from":"0x08d5cb97517f8a7189b7b9f34ca26f554827179f","data":"0x608060405234801561000f575f80fd5b506108f28061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c80632e64cec1146100595780636057361d146100775780636f760f41146100935780638bab8dd5146100af5780639e7a13ad146100df575b5f80fd5b610061610110565b60405161006e919061029f565b60405180910390f35b610091600480360381019061008c91906102f3565b610118565b005b6100ad600480360381019

Could somebody tell me what is going on please?

0

There are 0 answers