[Ethereum] Solidity : Error encoding arguments: Error: invalid BigNumber string

ethersmart-contract-walletssolidity

I just begun to learn solidity by following a youtube video(https://www.youtube.com/watch?v=M576WGiDBdQ).
This is duplicated question for Why do I keep getting invalid argument?, but I can't resolve the problem with the answer on the article.
And I have not enough reputation for post a comment.

Entire code is as below.(and it works fine on the video)

pragma solidity ^0.6.0;

contract SimpleStorage {
    
    // This will get initialized to 0!
    uint256 favoriteNumber;
    bool favoriteBool;

    struct People {
        uint256 favoriteNumber;
        string name;
    }
    
    People[] public people;
    mapping(string => uint256) public nameToFavoriteNumber;

    function store(uint256 _favoriteNumber) public {
        favoriteNumber = _favoriteNumber;
    }

    // view, pure
    function retrieve() public view returns(uint256) {
        favoriteNumber + favoriteNumber;
    }

    function addPerson(string memory _name, uint256 _favoriteNumber) public{    
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }
    
}

Other features are working with no errors but the accessing 'people' keeps give me a error

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

kassé suggested on the article(Why do I keep getting invalid argument?)

when you deploy put 0 on the people variable and click on it after you
can add with de addPerson function. Also if you want to add second
person put 1 to people and after add another one

I tried modify code as below:

People[0] public people;

and

People[1] public people;

It gives me below message

contracts/SimpleStorage.sol:12:12: TypeError: Array with zero length specified.

and

contracts/SimpleStorage.sol:23:9: TypeError: Member "push" not found or not visible after
argument-dependent lookup in struct SimpleStorage.People storage ref[1] storage ref.

Please advise me if there is any other suggestion.

Best Answer

I'm also learning from fcc haha. Not sure if you still need it but just in case if others also encounter similar problem. I don't think you're supposed to change "People[0] public people;" or "People1 public people;"

Just leave it as

People[] public people;

If I'm not wrong, you're supposed to change the people value here to 0 as it is blank by default. (the code by freecodecamp is correct)

Related Topic