'Solidity - Invalid BigNumber string (argument="value" value="" code=INVALID_ARGUMENT version=bignumber/5.4.2)

solidity newbie here. when I try to read the value of the people array. I'm getting an error:

call to SimpleStorage.people errored: Error encoding arguments: Error: invalid BigNumber string (argument="value" value="" code=INVALID_ARGUMENT version=bignumber/5.4.2)

my compiler version is 0.6.6. not sure what's wrong? any suggestions?

// SPD-License_Identifier: MIT

pragma solidity ^0.6.0;

contract SimpleStorage {
    uint256 favNum;
    
    struct People {
        uint256 favNum;
        string name;
    }
    
    People[] public people;
    
    function store(uint256 _favNum) public {
        favNum = _favNum;
    }
    
    function retrieve() public view returns(uint256) {
        return favNum;
    }
    
    function addPerson(string memory _name, uint256 _favNum) public {
        people.push(People(_favNum, _name));
    }
}


Solution 1:[1]

The error happens when you're trying to call the people() function (from Remix IDE) without passing any value.

Since the People[] public people is a public property, it autogenerates a getter function during compilation. But because it's an array, the getter function requires an uint256 param specifying the index of the array that you want to retrieve.

When you pass an empty string, Remix tries to encode it to the BigNumber instance, but this fails. Only when you pass an (existing) index of the array, it works correctly:

people() call


If you want to get the whole array in one call, you need to create a separate getter function:

function getAllPeople() public view returns (People[] memory) {
    return people;
}

getAllPeople() call

Solution 2:[2]

I had this error just to find out that i missed to pass a parameter to my function that's expecting unit256

Solution 3:[3]

You must click on the small arrow to the right of the deploy button, then the fields will be displayed so that you can complete the data that the contract must receive. enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Hejda
Solution 2 alisidaniel
Solution 3 Ale DC