Problems making calls using Moralis.executeFunction

Hi everyone, I am very new to Moralis but I am working on a project that is soon due and I cannot figure out how to make write calls to my contract. Some background, I am not using any Moralis online service so I do not have API key plugged in my project. I understood that fro basic calls to the blockchain I do not need access to the API. The way I called my view functions was via const { runContractFunction: functionName } = useWeb3Contract({ ....abi, addresss....}) and then I would just do something like onClick = {async function () { await functionName(...);}} This works fine and I able to get data back. The problem arises when I try to write to my contract and get some returned value back. Since parameters I want to pass to the contract change dynamically, I figured I cannot use useWeb3Contract hook since after it gets initialized I cannot edit the params anymore. Then I tried to make use of await Moralis.executeFunction(getProposalInfo); but then I get one very weird error. I attached screenshot. Here is also link to my component. Thanks!

Link to code: https://drive.google.com/file/d/1I0OjmuEoVO_OKc-3qatj97Aj51BAfs-l/view?usp=sharing

I figured the problem. It was actually very stupid, the getProposalInfo should have {…contractAddress: …} field, but in my case it was {…address: …}. Either there was a mistake on some forum where I got this snipped from or I made it.

However, I would like if someone can confirm to me weather my premise that I do not need API key for most of the things is correct?

Hi, yes, an api key will be required

For which features if you can specify? So if eventually something does not work I know that the API key could be the reason.

All the functions under Moralis.Web3API are using the api key. In your case runContractFunction is using the api key. The ones that are not using the api are the functions that are editing the database, the ones calling cloud functions, and Moralis.executeFunction also doesnt use the api

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.