1

I am trying to deploy a contract to a local ganache network using Nodejs v20. Nodejs is able to connect with local Ganache but the deploy() method is giving following error:

Error: missing revert data (action="estimateGas", data=null, reason=null, transaction={ "data": "0x608060405234801561000f575f8....", "from": "0xfeBaeDDecD30....", "to": null }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.6.1)

info: {
    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: [Object]
    },
    payload: {
      method: 'eth_estimateGas',
      params: [Array],
      id: 4,
      jsonrpc: '2.0'
    }
  }

It is trying to call this eth_estimateGas function and it fails. I am using solcjs to compile the Solidity contract using the command

solcjs --bin --abi SimpleStorage.sol

These are the versions:

"dependencies": {
    "ethers": "^6.6.1",
    "fs-extra": "^11.1.1",
    "solc": "0.7"
 }

Below is the code for Nodejs

async function main() {
  // http://127.0.0.1:7545  RPC URL for Ganache
  const provider = new ethers.JsonRpcProvider("http://192.168.2.17:8545");

  const wallet = new ethers.Wallet(
    "0xe75a169f....",
    provider
  );

  provider.getCode()

  const abi = JSON.parse(
    fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi").toString()
  );
  const binary = fs
    .readFileSync("./SimpleStorage_sol_SimpleStorage.bin")
    .toString();

  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  await contractFactory.deploy();
}

Below is the code for the smart contract

*// SPDX-License-Identifier: MIT
pragma solidity >=0.8.6;

contract SimpleStorage {
    uint256 public favoriteNumber;

    function store(uint256 _favoriteNumber) public virtual {
        favoriteNumber = _favoriteNumber;
    }

    function retrieve() public view returns (uint256) {
        return favoriteNumber;
    }
}

3 Answers 3

1

I was able to fix the problem by using the below versions of both solcjs & Solidity

0.8.19

Also while compiling the code with solcjs make sure the version is 0.8.19 I used npx solcjs for this

1

i was able to fix my problem by giving the gas prices and the gas limit

  const overrides = {
    gasLimit: 6721975, // Adjust the gas limit as needed
    gasPrice: ethers.parseUnits("20000000000", "wei"), // Adjust the gas    price as needed
  };
const contract = await contractFactory.deploy(overrides);
0

I was using a newer version of solc and was seeing the same error. To fix:

  1. yarn remove solc
  2. yarn add [email protected]
  3. Recompile contract and deploy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.