adrianhajdin / project_crowdfunding

With a stunning design, connected to the blockchain, metamask pairing, interaction with smart contracts, sending Ethereum through the blockchain network, and writing solidity code.
https://jsmastery.pro
710 stars 384 forks source link

Error: Function "getDonators" requires 1 arguments, but undefined were provided. #31

Open Gola-k opened 1 year ago

Gola-k commented 1 year ago

This is the Error image

And this is the function in the index.js file of context folder image

can someone tell me what should i change in the function to pass the argument pId as it is not getting accepted It is showing on the console.log(pId) just before it but not getting passed as an argument.

@adrianhajdin

Gola-k commented 1 year ago
const getDonations = async (pId) => {
    // console.log(pId);
    const donations = await contract.call('getDonators', [pId]);
    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;
}

If I am using [pId] instaed of pId then the project is working fine but why is this happening, should I change all the pId with [pId] in the project as I am still getting this warning :

Warning: Each child in a list should have a unique "key" prop.

Check the render method of DisplayCampaigns. See https://reactjs.org/link/warning-keys for more information. at FundCard (http://localhost:5173/src/components/FundCard.jsx:21:3) at DisplayCampaigns (http://localhost:5173/src/components/DisplayCampaigns.jsx:22:3) at Home (http://localhost:5173/src/pages/Home.jsx?t=1680864746379:22:37) at RenderedRoute (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=3a287555:3040:5) at Routes (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=3a287555:3403:5) at div at div at App at StateContextProvider (http://localhost:5173/src/context/index.jsx?t=1680864746379:22:3) at Router (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=3a287555:3350:15) at BrowserRouter (http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=3a287555:3769:5) at ThirdwebAuthProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5144:5) at WrappedThirdwebSDKProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5289:5) at QueryClientProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:4851:3) at QueryClientProviderWithDefault (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5063:5) at ThirdwebConnectedWalletProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5216:5) at ThirdwebConfigProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5195:5) at ThirdwebSDKProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5380:5) at ThirdwebSDKProviderWrapper (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5688:5) at ThirdwebWalletProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5445:58) at ThirdwebProviderCore (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:5640:5) at ThemeProvider2 (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:9117:44) at WalletUIStatesProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:24896:83) at ThirdwebProvider (http://localhost:5173/node_modules/.vite/deps/@thirdweb-dev_react.js?v=3a287555:27268:5)

@adrianhajdin

A-Pradeep commented 1 year ago

@Gola-k

Each child in a list should have a unique "key" prop. For this you need to add Key on the component and it would go away. Not a major blocker.

Coming to the issue, [pId] is the correct format for sending data to thirdweb.

As per the Thirdweb const data = await contract.call("getDonators", [_id])

In video, it's sending directly but seems there is a recent update in SDK.

akashpanda122 commented 1 year ago

Hey @Gola-k

How did you solve the problem? I'm also getting the same problem

akashpanda122 commented 1 year ago

I'm also getting the error with the previous one ->

Error: Function "donateToCampaign" requires 1 arguments, but undefined were provided.

Gola-k commented 1 year ago

I'm also getting the error with the previous one ->

Error: Function "donateToCampaign" requires 1 arguments, but undefined were provided.

As you can see above I have put the argument pId in square brackets while calling the smart contract function in both donate and getdonations function

Gola-k commented 1 year ago

And for the warning you have to change the smart contract which I have not solved as it is working fine even with the warnings

A-Pradeep commented 1 year ago

@Gola-k

Each child in a list should have a unique "key" prop. For this you need to add Key on the component and it would go away. Not a major blocker.

Coming to the issue, [pId] is the correct format for sending data to thirdweb.

As per the Thirdweb documentation const data = await contract.call("getDonators", [_id])

In video, it's sending directly but seems there is a recent update in SDK.

@akashpanda122 as per the thirdweb documentation, you need to send the id { in our usecase the variable name is pId } as array in parameter, as below. const data = await contract.call("getDonators", [pId]) this would solve the issue.

@Gola-k As far I know and best of my knowledge, the Key error has nothing to do with the smart contract. The warning : Each child in a list should have a unique "key" prop. is by React. In simpler way - As you are rendering the div, the react need key to keep track of its Dom change. So add a key to rendering div and it would solve Key warning.

Happy coding.

Brijesh-Adeshara commented 1 year ago

at the time of fund campaign , no metamask notification is popped up for confirmation instead it showing "the transaction is in progress please wait " in the screen.. can anyone have solution for this?

A-Pradeep commented 1 year ago

@Brijesh-Adeshara Can you check errors in console.

Brijesh-Adeshara commented 1 year ago

@A-Pradeep no erros are there in console, earlier the erros were of pid but after putting pid in square bracket no errors were there , only some warnings are there in the console.

Brijesh-Adeshara commented 1 year ago

and it continuously showing "the transaction is in progress please wait till the transaction is completed"

Brijesh-Adeshara commented 1 year ago

@A-Pradeep Thanks now it is showing metamask notification dont know why but after checking 4 to 5 times it is appeared

Gola-k commented 1 year ago

@Brijesh-Adeshara did you check the metamask extension ( after clicking on confirm for the metamask notification ) for the pending transaction if the transaction is pending then it is taking time due to network being busy and transaction being of low value (especially if you are using goerli) and if their is no transaction pending in the metamask extension then I don't know you need to find the errors in the code you can compare it with the GitHub code

Gola-k commented 1 year ago

@A-Pradeep Thanks now it is showing metamask notification dont know why but after checking 4 to 5 times it is appeared

Good for you

arslanmaqsood713 commented 1 year ago

Thanks for helping us for fixing the errors.

arslanmaqsood713 commented 1 year ago

Thanks for helping us for fixing the errors.