0

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];
    }
}
4
  • 1
    Because fundsByBidder[msg.sender].length is not larger than _goodsId. Commented Jul 25, 2020 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
    Commented Jul 25, 2020 at 15:43
  • The length of your array is 0, so you cannot access any element in it. Commented Jul 25, 2020 at 16:26
  • Invalid opcode is similar to "runtime exception."
    – hrkrshnn
    Commented Jul 26, 2020 at 17:51

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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