From solidity:
TypeError: Return argument type address payable[] storage ref is not implicitly convertible to expected type (type of first return variable) address. --> contract.sol:32:16: | 32 | return players; | ^^^^^^^
function getPlayers() public view returns (address) {
return players;
}
I am trying to return the number of players in the array. any help? solidity 8.16
CodePudding user response:
You are returning the entire array. Since you want the length of the array, the return value length of the array is uint type. change the returns
type to uint
function getPlayers() public view returns (uint) {
return players.length;
}
If you want to return the array itself
// error states this: type address payable[]
function getPlayers() public view returns (address payable[] memory ) {
return players;
}