Migrations hit an invalid opcode while deploying

660 views Asked by At

When run truffle migration command it throws error, Tried many solutions but couldn,t corrected it. PS C:\Users\Jatin\OneDrive - nsut.ac.in\Desktop\Truffle\web> truffle migration

Compiling your contracts...

Compiling .\contracts\Migrations.sol Compiling .\contracts\demo.sol Artifacts written to C:\Users\Jatin\OneDrive - nsut.ac.in\Desktop\Truffle\web\build\contracts Compiled successfully using:

  • solc: 0.8.20+commit.a1b79de6.Emscripten.clang

Starting migrations...

Network name: 'development' Network id: 5777 Block gas limit: 6721975 (0x6691b7)

1_initial_migration copy.js

Deploying 'Migrations'

*** Deployment Failed ***

"Migrations" 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 ***

"Migrations" 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\Jatin\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:330:1

Truffle v5.9.3 (core: 5.9.3) Node v18.16.0

I try many solutions to fix it but didn't solve it

1

There are 1 answers

0
Adam Boudj On

We encountered similar issue in past. It is because of the new opcode PUSH0 introduced in Solidity version 0.8.20.

By the way Truffle is now discontinued. To ensure smooth and secure development, I highly suggest switching to Hardhat.

Here is how you can configure your hardhat config:

module.exports = {
  solidity: {
    version: "0.8.20",
    settings: {
      evmVersion: "paris"
    }
  }
};

Alternatively you can use Foundry which also good