Ok, so first, I deployed Sushi and Link token contracts, only change i made was to add this into the constructor on each:
_mint(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,10000 * 10 ** decimals());
So the deployer and 2nd address of the list in remix will have a balance on each contract of that amount of tokens, (after deployment, i called balanceOf
to verify that both addresses have a balance of each).
Last, deploy the mainContract, after it, i use getBalance
and the result was showed properly
Calling getBalances
, the array must be send on this way:
["address1", "address2"]
Your function will fail because of a revert without no pointer to, so the only change i made was to specify the length of the array that you will return, that way, your function was able to return the result of balances based on the struct.
So the function looks like this in order to work.
function getBalances(address user, address[] memory tokens) view public returns(Token[] memory){
Token[] memory tokenBalances = new Token[](tokens.length);
for(uint i = 0 ; i < tokens.length ; i++){
tokenBalances[i] = getBalance(user, tokens[i]);
}
return tokenBalances;
}
PD: the trick here is to specify the length of the array you will return, basic syntax for it is;
uint _length = 5;
// arrayType[](lengthOfArray)
uint [] exampleArray = new uint[](_length);
Hope this helps
Carlos Z