2

I've seen sample code in various places that have public arrays, but when I try to create this contract in Remix:

pragma solidity ^0.4.19;
contract Ballot {
  uint8[] public proposals;
}

It always fails with

undefined errored: VM error: invalid opcode.
invalid opcode  The constructor should be payable if you send value.
    The execution might have thrown.
    Debug the transaction to get more information.

Again, this is during the creation of the contract. I've tried sending value (and adding a payable constructor); the error changes (VM error: revert.), but still does not succeed. I've also tried debugging; it steps through the constructor (if present), and then steps through the state field and fails there.

  • 1
    The code you posted compiles and works with Remix and solc compiler version 0.4.19. It's not clear how exactly to replicate the error (not obvious). You can generally ignore the "payable" aspect of the constructor failure message. It's a boilerplate hint. The message just means the constructor (not shown) failed. – Rob Hitchens - B9lab Dec 11 '17 at 23:24
  • @RobHitchens I was able to compile but I get the error when clicking the Create button on the Run tab. There is no constructor. – Stephen Cleary Dec 12 '17 at 2:09
  • 2
    It does give the error but if you check to the right under the create button you'll see that your contract was created. – I.B Dec 12 '17 at 2:20
  • @CNuts: True. And it also gives that same error when I call some functions, but they also appear to be working. Please post your comment as an answer. – Stephen Cleary Dec 12 '17 at 3:28
  • TBH I'm not feeling it yet with the new Remix and I lost sight of how most people are probably not using yann300.github.io/remix04. Your contract is fine. I see the error now. No, it doesn't add up for me. – Rob Hitchens - B9lab Dec 12 '17 at 3:59
0

It does give the error but if you check to the right under the create button you'll see that your contract was created.

enter image description here

  • Also, the same error is spit out when functions on the contract are called. The error is displayed after the successful function result. My mind just saw the error as the last message, assumed it failed, and didn't scroll up to see those functions were actually succeeding. – Stephen Cleary Dec 12 '17 at 14:27
0

You get "VM Exception: invalid opcode" error in solidity, when I you had set a value in the "value input" before creating the contract. So, to resolve such error you can set "value input" to 0 and retry to create the contract. It will work fine.

  • Setting the value to something else than 0 will cause an error without creating the contract. Having 0 as value will still generate the same error but will create the contract. – I.B Dec 12 '17 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.