Reputation: 69
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
Reputation: 43481
The error happens when you're calling the house()
auto-generated getter function without providing a parameter.
The house
is a one dimensional array, so you need to choose which index do you want to access.
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