Your setup looks fine, so far as I can see (as long as the serverUrl and appId are correct)
Provider does seem to work sometimes
What do you mean with sometimes? When does it work and when does it not work? Also when it does not work, what seems to be the issue?
It might be possible that you call Moralis functions directly when the app loads, even before Moralis is initialized. If this is the case, then you can check if isInitialized
is true
.
web3 useMoralis() is null
This happens when you are logged out. Web 3 is enabled and well be possible to call via const { web3 } = useMoralis()
once the user is logged in. We can take a look if we can provide the option to enable web3 by default. But currently, it is only accessible when a user is logged in.
Of course, you can always use your own web3 library as well. (web3 or ethers for example)
TypeError: Cannot read property ‘eth’ of null when trying to use web3 to declare contract
This probably also happens before the user is authenticated. In that case, web3 is not available and thus null. (see my comment above)
So in general, I would advise to only use web3, when a user has been authenticated for now. Or use your own web3 library.
For the inconsistencies, that seems weird to me. Maybe this is because sometimes you are logged in and sometimes not? Please share the code of where this happens and how to reproduce this.