Can i call useWeb3ExecuteFunction without connecting a wallet?


I am using react-moralis.

I am having trouble calling useWeb3ExecuteFunction when a wallet is not connected.

What i want to achieve is to query a smart contract, let’s say “total supply” which shouldn’t need to have a wallet connected. Currently useWeb3ExecuteFunction is returning null for the data.

Any advice on how to do this?

I’ve tried useApiContract().

Which states … “Execute a on-chain contract’s function. It calls Moralis API and doesn’t require web3 to be enabled.”

Error: Web3Api not initialized, run Moralis.start() first
at Function.



Can we see your useWeb3ExecuteFunction code.

For the second one, if it wants you to run Moralis.start(), it means you need to connect to your server to then use the Moralis API. When it says web3 it’s probably referring to a provider.

You can use runContractFuncrion without needing a wallet connection

Ok. It seems to work if i wait until

const { Moralis, isInitialized, isInitializing } = useMoralis();

useEffect(() => {
if (isInitialized && !isInitializing) {
}, [isInitialized, isInitializing]);

However, it is very very slow and doesn’t seem too neat.

It should be reasonably fast to get a totalSupply, can you run code similar to this example? Web3API.native - Moralis