I am trying to do an Auction project and this part is bugging me. I can't figure out what is the problem that's causing the following error message: "VM error: invalid opcode.". Even if I do this simple smart contact I get the same error message. So I would like it if someone can figure out what is the problem with the provided smart contract. Thanks!

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.0 < 0.7.0;

contract testing {
    mapping(address => uint256[]) fundsByBidder;
    mapping(uint256 => uint256) newBidToGoods;
    function update(uint256 _goodsId) public payable {
        newBidToGoods[_goodsId] = fundsByBidder[msg.sender][_goodsId] + msg.value;
    function show(uint256 _goodsId) public view returns(uint256) {
        return newBidToGoods[_goodsId];
  • 1
    Because fundsByBidder[msg.sender].length is not larger than _goodsId. – goodvibration Jul 25 at 15:31
  • @goodvibration Can you help me out a bit more? I'm not sure that I fully understand what is the problem and how to fix it. – Nikola Jul 25 at 15:43
  • The length of your array is 0, so you cannot access any element in it. – goodvibration Jul 25 at 16:26
  • @goodvibration Thanks! – Nikola Jul 25 at 16:42
  • Invalid opcode is similar to "runtime exception." – hrkrshnn Jul 26 at 17:51

Because fundsByBidder[msg.sender].length is not larger than _goodsId.

| improve this answer | |

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.