Working with moralis
and react-moralis
, it looks like there are several ways to execute functions, but I’m having a hard time understanding which does what? What are the tradeoffs of each?
Moralis SDK has all the core functionality and is implemented in Vanilla JS.
When using the core SDK, executing functions will require you to handle promises and plain JS manipulations.
However, if you want a wrapper for react that handles all these function call promises behind the scenes, react-moralis is the way to go.
The underlying functionality is still the core Moralis SDK under the react-moralis package, so it might look different when writing code, but it works the same.
Thanks
Thanks! That makes sense.
So what about useApiContract
, useWeb3ExecuteFunction
, and useWeb3Contract
…
I get that these are all hooks… but what is their difference?
-
useApiContract
: Calls the Moralis API and doesn’t require metamask to be enabled. -
useWeb3Contract
: Executes a contract without calling moralis API (needs metamask) -
useWeb3ExecuteFunction
: The same asuseWeb3Contract
? Is this forcalls
instead ofsends
? (Not actually spending gas) -
useMoralisWeb3Api
: Everything in the Moralis.Web3API as a hook -
Moralis.executeFunction
: Execute a function without a hook
Is this right?
Yes, You are absolutely right.
Regarding the above, as you can see it is defined here too. useWeb3Contract uses useWeb3ExecuteFunction() under the hood.
No there is no difference between calls and sends between these two functions.
Hope this clears it out.
Thanks for the help. Maybe I’m doing something wrong… I can’t seem to get useWeb3Contract
working correctly. I don’t get an error or anything. I’m wondering if you know where there are some examples in the wild of this? The ethereum-boilerplate doesn’t use useWeb3Contract
.
Idk what I was doing, but all things are working now. Thanks.
When in doubt, walk through the process of making an issue and try to reproduce, and boom. Problem solved.
Thanks