Hi, I have a problem when executing a web3 function that send data to the smart contract.
See this function as setting a price for ERC-1155 collection where the collection has 2 or more different items in it. When I run the function through remix it works fine. But when I call the function is called through my react app using Moralis, the price does not update correctly. Example and code below:
My function in the ABI:
"inputs": [
{
"internalType": "uint256[]",
"name": "_priceList",
"type": "uint256[]"
},
{
"internalType": "uint256[]",
"name": "_ids",
"type": "uint256[]"
}
],
"name": "setPriceForAll",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
const handleOk = async () => {
setConfirmLoading(true);
let ids = [];
let listPrices = []
for(let k = 0; k<props.numberOfTiers;k++) {
if(priceTier[`tier${k}`] !== undefined && priceTier[`tier${k}`] !== null){
listPrices.push(priceTier[`tier${k}`]);
ids.push(k);
}
}
console.log(ids, listPrices); // I logged to make sure value match what I expect
let options = {
chain: "rinkeby",
contractAddress: props.contractAddress,
functionName: "setPriceForAll",
abi: props.abi,
params : {
_priceList : [listPrices],
_ids : [ids]
}
}
try {
let tx = await Moralis.executeFunction(options)
await tx.wait()
.then(() => {
console.log(tx);
})
} catch (error) {
console.log(error.message);
} finally {
setConfirmLoading(false);
}
}
Letâs say my ids are 0 and 1 and the price associated with them are 50 and 210 respectively. The function will run but the price set for each ID will be different: for ID 0 I will get a price of whatever the value was set to before (by default itâs 0) and for the second I get 210. I am not sure whatâs going on here to be honest.
Also if I only update a signle value so letâs say ID 1 I set to price 500, it works correctly.