1

this is my Solidity code

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

// pragma solidity ^0.8.0;
// pragma solidity >=0.8.0 <0.9.0;

contract SimpleStorage {
    uint256 favoriteNumber;

    struct People {
        uint256 favoriteNumber;
        string name;
    }
    // uint256[] public anArray;
    People[] public people;

    mapping(string => uint256) public nameToFavoriteNumber;

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

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

    function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }
}

and this is my deploy.js

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(
    "0x489c469db7e6049896d646f6233942fb0c5b2b348aed3965ce52e0517587689f",
    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("Contract is deploying please wait...");
  const contract = await contractFactory.deploy();
  console.log(contract);
}

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

I am getting the following error

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'
    }
  }
}

What can be the solution?

1 Answer 1

0

You probably deployed on an chain whose execution layer doesn't support newer opcodes such as PUSH0. If you used the one from chains which have not introduced this opcode, this is what may happen. You can look at opcode differences, here for instance Linea as of time of writing doesn't support PUSH0 https://www.evmdiff.com/features?feature=opcodes

Related: Invalid opcode in smart contract ( solidity ) while using ganache-cli

1
  • Thankyou Franfran for your help let me try it once again... Commented Jun 30 at 8:25

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.