Hello,
When using executeFunction to call a contract function, how do I pass parameter value if it is an array?
For example, I have the following contract function (ABI Below):
{
"inputs": [
{
"internalType": "uint256[]",
"name": "streamIdList",
"type": "uint256[]"
},
{
"internalType": "address",
"name": "who",
"type": "address"
}
],
"name": "balanceOfStreams",
"outputs": [
{
"internalType": "uint256",
"name": "totalBalance",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
streamIdList
And I am using the code below to call the function:
const [userStreams, setUserStreams] = useState([]);
.
.
console.log("----> userStreams(length): " + userStreams.length);
console.log("----> userStreams: " + JSON.stringify(userStreams));
const currentUser = Moralis.User.current();
console.log("----> currentUser.get('ethAddress'): " + currentUser.get("ethAddress"));
if (userStreams.length > 0) {
const userStreamsIdList = userStreams.map(Number);
console.log("-----> userStreamsIdList: " + JSON.stringify(userStreamsIdList));
const balaceOfStreams = Moralis.executeFunction({ functionName: 'balanceOfStreams',
params: {
streamIdList: userStreams,
who: currentUser.get("ethAddress")
},
...streamContractOptions
});
console.log("----> balaceOfStreams: " + JSON.stringify(balaceOfStreams));
}
in the console log, I see the following:
----> userStreams(length): 3
----> userStreams: ["100000","100001","100002"]
----> balaceOfStreams: {}
I am expecting to get back a non-empty result. I verified the same call using a different front-end and I do get the proper balance. Am I passing the array in the correct format?
Thanks in advance!