[Ethereum] Remix IDE getting VM error invalid opcode

dappsidemetamaskremixsolidity

I am attempting to deploy a test contract on javascriptVM using Remix IDE in chrome. However when I try to execute the contract I receive this message in the status section.

"transact to Notes.addNote errored: VM error: invalid opcode. invalid
opcode The execution might have thrown. Debug the transaction to
get more information. "

pl let me know if anything wrong in mycode..

Best Answer

Invalid opcode can be the result of either one of the following runtime operations:

  1. assert of an expression which evaluates to false
  2. array[i] where i >= array.length

In your code, only the second option appears viable.

It is viable in the expression userNotes[msg.sender][_noteId].

So the error must be the result of _noteId >= userNotes[msg.sender].length.

Related Topic