0

I'm receiving the following error message trying to deploy a very simple contract to Ganache. How can I resolve this?

Contract:

pragma solidity ^0.8.21;  // ^0.4.24; 

contract HelloWorld {
    string private helloMessage = "Hello world";

    function getHelloMessage() public view returns (string memory) {
        return helloMessage;
    }
}

Error Message following "truffle deploy --reset" command:

===========================
> Compiling .\contracts\HelloWorld.sol
> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> project:/contracts/HelloWorld.sol


> Artifacts written to C:\Users\markp\workspace\firstProject_Source\build\contracts
> Compiled successfully using:
   - solc: 0.8.21+commit.d9974bed.Emscripten.clang


Starting migrations...
======================
> Network name:    'development'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


2_contracts_migration.js
========================

   Deploying 'HelloWorld'
   ----------------------
 *** Deployment Failed ***

"HelloWorld" hit an invalid opcode while deploying. Try:
   * Verifying that your constructor params satisfy all assert conditions.
   * Verifying your constructor code doesn't access an array out of bounds.
   * Adding reason strings to your assert statements.


Exiting: Review successful transactions manually by checking the transaction hashes above on Etherscan.

Error: Deployment Failed

"HelloWorld" hit an invalid opcode while deploying. Try:
   * Verifying that your constructor params satisfy all assert conditions.
   * Verifying your constructor code doesn't access an array out of bounds.
   * Adding reason strings to your assert statements.

 at C:\Users\markp\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:330:1  
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Truffle v5.11.5 (core: 5.11.5)
Node v18.18.2
PS C:\Users\markp\workspace\firstProject_Source>
1
  • Can you add the contents of 2_contracts_migration.js since this is where the issue seems to be? The contract code itself is fine.
    – Ake
    Oct 20, 2023 at 23:13

1 Answer 1

0

The 0x5f PUSH0 opcode was added with the Shanghai upgrade, and was supported from solc version ^0.8.20.

Perhaps your local ganache chain is running on an older EVM version, hence the conflict with your 0.8.21 compiler version.

Try compiling with 0.8.19, or looking at your ganache settings.

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.