Saving migration to chain.Error: Returned error: VM Exception while processing transaction: invalid opcode

@dan-i
Hi, I’m struggling with “How to Build Serverless Dapps Part 1 - Web3.js & Moralis Programming Tutorial” I can’t use migrate.

I’ve cloned the files from GitHub, entered my Moralis App id, and server into main.js.
and when trying to migrate, it can’t find ganache server, so i edit truffle config and run “truffle migrate --reset --network development”

then it starts compiling and i get this:

2_contract_migration.js
=======================

   Deploying 'FlipContract'
   ------------------------
   > transaction hash:    0x1c7780ef6814fbb69a9be13217e064c9c270de3033e3c643319d46acbbe648ab
   > Blocks: 0            Seconds: 0
   > contract address:    0x56B68B51a46ED785f7fc0353d104114E04CB9B76
   > block number:        27
   > block timestamp:     1617036598
   > account:             0xE0190cAf00005a9Eeb4556B0D59e3FbDd171060f
   > balance:             99.32721786
   > gas used:            853046 (0xd0436)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.01706092 ETH


   ⠋ Saving migration to chain.Error: Returned error: VM Exception while processing transaction: invalid opcode
Error: Returned error: VM Exception while processing transaction: invalid opcode

----------- then a lot of stuff, tried to save it as a file, but its 47mb of text --------------------

RuntimeError: abort(Error: Returned error: VM Exception while processing transaction: invalid opcode). Build with -s ASSERTIONS=1 for more info.
    at process.abort (/Users/alex/.config/truffle/compilers/node_modules/soljson-v0.7.5+commit.eb77ed08.js:1:13877)
    at process.emit (events.js:198:13)
    at process.emit (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/source-map-support/source-map-support.js:495:1)
    at processEmit [as emit] (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/signal-exit/index.js:155:1)
    at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)
    at process._tickCallback (internal/process/next_tick.js:69:34)

Hi @voljumet

This looks like a require statement that fails in your contract.

Is there a require in your constructor?
Are you calling a function from your migration file?
The issue is somewhere there :slight_smile:

Check it out and if you cannot spot it, create a repo on GitHub, push your project and share the code.

Cheers,
Dani

@dan-i thanks for the response,
I cloned from “https://github.com/MoralisWeb3/demo-apps/tree/main/casino-dapp
and the only changes I did was to add id and URL to main.js, and in truffle-config.js:

development: {
      host: "127.0.0.1", // Localhost (default: none)
      port: 7545, // Standard Ethereum port (default: none)
      network_id: "*", // Any network (default: none)
    },

not sure why it is not working
here is my repo: https://github.com/voljumet/casino
when i installed openzeppelin, i used “npm install @openzeppelin/contracts@3” to get a version that uses solidity version less than 0.8.0

Hi @voljumet

I was able to clone your repo and migrate the project without errors.
Proceed as follow:

  • Make sure to be inside the folder truffle;
  • Run truffle develop;
  • Run migrate --reset;

Screenshot 2021-03-30 at 15.30.00

Let me know,
Dani

aaaaaah, “truffle develop” is the thing i missed :sweat_smile: tyvm!

1 Like

Hey @voljumet

Truffle develop runs a local blockchain that you need otherwise truffle does not know where to deploy.
Closing the issue.

Cheers,
Dani