The inbox.sol file is -

//SPDX-License-Identifier: UNLICENSED

pragma solidity ^ 0.8.9;

contract Inbox {

    string public message;

   function myInbox(string memory initialMessage) public {
    message = initialMessage;
    function setMessage(string memory newMessage) public {
        message = newMessage;

The inbox.test.js file is -

const ganache = require('ganache-cli');
const Web3 = require('web3');
const { abi, bytecode } = require('../compile');
const provider = ganache.provider();
const web3 = new Web3(provider);

let accounts;
let inbox;

beforeEach(async () => {
  accounts = await web3.eth.getAccounts();

  inbox = await new web3.eth.Contract(abi)
    .deploy({ data: bytecode, arguments: ["Hi"] })
    .send({ from: accounts[0], gas: "1000000" });

describe('Inbox', () => {
  it('deploys a contract', () => {


The error i keep on getting is below

    1) "before each" hook for "deploys a contract"

  0 passing (445ms)
  1 failing

  1) "before each" hook for "deploys a contract":
     c: VM Exception while processing transaction: invalid opcode
      at Function.c.fromResults (node_modules\ganache-cli\build\ganache-core.node.cli.js:4:192547)
      at w.processBlock (node_modules\ganache-cli\build\ganache-core.node.cli.js:42:50957)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

> **Please help me with the error**

1 Answer 1


I must ask what version are you using for compilation. Because as I see you are using a floating pragma which is ^0.8.9. This might cause a problem when you are compiling with version 0.8.20.

This is because solidity 0.8.20 introduces the PUSH0(0x5f) opcode which is only supported on the ETH mainnet and not on any other chains. That's why other chains can't find the PUSH0(0x5f) opcode and throw this error.

Consider using 0.8.19 for other chains.

This should solve your problem.

If you want to learn more about PUSH0 opcode you can check this small article which explains it pretty well. https://www.zaryabs.com/push0-opcode/

EDIT - If you just installed Truffle and want to use older version of Solidity, you can simply specifying the compiler version in the truffle-config.js file:

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.19", // Fetch exact version from solc-bin (default: truffle's version) 
  • I haven't installed truffle and am using ganache-cli. Kindly, provide a solution according to ganache-cli and i am providing the pacakage.json file below for versions information. { "name": "inbox", "version": "1.0.0", "description": "", "main": "compile.js", "directories": { "test": "test" }, "scripts": { "test": "mocha" }, "author": "", "license": "ISC", "dependencies": { "ganache-cli": "^6.12.2", "mocha": "^10.2.0", "solc": "^0.8.19", "web3": "^4.0.1" } }
    – Swetha N
    Jun 22, 2023 at 13:59
  • Hey, at the time of compilation just use 0.8.19 instead of 0.8.20. This is probably a solution. If it doesn't work then we can think of another problem. Jun 23, 2023 at 6:04
  • I tried, now it is giving an error of ```Web3 is not a constructor.
    – Swetha N
    Jun 24, 2023 at 7:03
  • Similar post ethereum.stackexchange.com/questions/50294/… Jun 24, 2023 at 14:34
  • 1
    It helped, thankyou so much.
    – Swetha N
    Jun 26, 2023 at 10:18

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.