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.
people
getter? Also did you try using a newer Solidity version? Handling structs as return values with older solidity versions resulted in returning tuples, which depends on the js library that you use how well it is supported.