I am receiving this error when trying to call the getUsers
getter function from the contract below: Invalid number of arguments to Solidity function
. Running on Truffle in develop mode.
mapping (address => User) Users;
address[] usersByAddress;
struct User {
string handle;
bytes32 city;
bytes32 state;
bytes32 country;
}
function registerNewUser(string handle, bytes32 city, bytes32 state, bytes32 country) returns (bool success) {
address thisNewAddress = msg.sender;
if(bytes(Users[msg.sender].handle).length == 0 && bytes(handle).length != 0){
Users[thisNewAddress].handle = handle;
Users[thisNewAddress].city = city;
Users[thisNewAddress].state = state;
Users[thisNewAddress].country = country;
usersByAddress.push(thisNewAddress);
return true;
} else {
return false;
}
}
//getters
function getUsers() view returns (address[]) { return usersByAddress; }
function getUser(address userAddress) view returns (string, bytes32, bytes32, bytes32) {
return (Users[userAddress].handle, Users[userAddress].city, Users[userAddress].state, Users[userAddress].country);
}
Let's say you deploy this contract in Truffle develop testnet and get an instance of the object x
. I can create a user by sending the transaction x.registerNewUser("Bob123","Orlando","FL","USA")
. Then I run x.getUser(web3.eth.accounts[0])
and get the following array:
[ 'Bob123',
'0x4f726c616e646f00000000000000000000000000000000000000000000000000',
'0x464c000000000000000000000000000000000000000000000000000000000000',
'0x5553410000000000000000000000000000000000000000000000000000000000' ]
This is expected since the last 3 elements in the array are type bytes32
. I expect x.getUsers
or x.getUsers.call()
to return an array of one address (my address at web3.eth.accounts[0]
) but instead get the invalid Solidity arguments
error even though there are no arguments passed into getUsers
.
Best Answer
try this one: