jjreedv
jjreedv

Reputation: 69

Smart Contract compiles fine but then screams about "BigNumber"

This compiles fine, but apon calling "house" I receive the following error:

Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.4.1)

anybody know why? thanks!

pragma solidity ^0.8.4;

contract Test {
     uint[] public house = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

    
    function sugMa() public view returns (uint) {
        uint even = 0;
        for (uint i = 0; i <= house.length; i++) {
            if (i % 2 == 0) {
                even += 1;
            }
        }
        return even;
    
    }

}

Upvotes: 0

Views: 624

Answers (1)

Petr Hejda
Petr Hejda

Reputation: 43481

The error happens when you're calling the house() auto-generated getter function without providing a parameter.

Calling without a parameter

The house is a one dimensional array, so you need to choose which index do you want to access.

Calling with a parameter


Solidity currently (v0.8) doesn't support calling a whole array from the auto-generated getter function. But - you can create your own function that returns the whole array.

function getHouse() external view returns (uint[] memory) {
    return house;
}

Then it returns

uint256[]: 1,2,3,4,5,6,7,8,9,10

Upvotes: 2

Related Questions