I'm using this function in my smart contract. It returns an uint256[] array containing the tokens that the user owns.
/**
* @dev Returns all of the tokens that the user owns
* @return An array of token indices
*/
function myTokens()
external
view
returns (
uint256[]
)
{
return ownedTokens[msg.sender];
}
In my web3 js console log, I get the below.
How do I read that array in my js code? Honestly, I don't understand the entire array. I just want to get the token IDs, which it supposed to return.
I'm expecting something like below as shown in Remix.
Here's my web3 js code.
async function retrieveTokenId(contract, walletAddress) {
await contract.methods.myTokens().call(function(err, res){
if(!err){
console.log(res);
} else {
console.log(err);
}
});
}
const array = await contract.methods.myTokens().call({ from: account });
array will have your array