Reputation: 11
I am building a crowdfunding blockchain application and I am getting the above error.
Uncaught (in promise) Error: Function "getDonators" requires 1 arguments, but undefined were provided. Expected function signature: contract.call("getDonators", _id: BigNumberish): Promise<string[], BigNumber[]>
This the code for the part where I am calling getDonators function
const getDonations = async (pId) => {
const donations = await contract.call('getDonators', pId); //HERE!
const numberOfDonations = donations[0].length;
const parsedDonations = [];
for(let i = 0; i < numberOfDonations; i++) {
parsedDonations.push({
donator: donations[0][i],
donation: ethers.utils.formatEther(donations[1][i].toString())
})
}
return parsedDonations;
}
This is the code that is present in the Solidity File
function getDonators(uint256 _id) view public returns (address[] memory, uint256[] memory) {
return (campaigns[_id].donators, campaigns[_id].donations);
Please help me resolve this issue. Am I not passing the parameters correctly ?
I tried to pass parameters in various ways but it didnt really fixed the issue. Also I tried to call the function(in .sol file) in a different manner like this :
await contract.donateToCampaign(pId, {
value: ethers.utils.parseEther(amount.toString())
});
Upvotes: 0
Views: 241
Reputation: 11
UPD : I actually resolved the error, replacing the erroneous line of code with :
const donations = await contract.call('getDonators', [pId]); //HERE!
https://portal.thirdweb.com/typescript/sdk.smartcontract.call
Upvotes: 1
Reputation: 359
The possible error I can see in your code is from this line:
const getDonations = async (pId) => {
The pId
may be undefined
in the first place.
Try to console.log
to see if it is actually an integer
const getDonations = async (pId) => {
console.log('pId:', pId); //Add the code here
const donations = await contract.call('getDonators', pId);
//...
Upvotes: 0