It didnât work.
I had to use user.get("ethAddress")
.
The issue with this solution though is that the user address doesnât get updated if I am switching wallet.
Is there something I am missing?
It didnât work.
I had to use user.get("ethAddress")
.
The issue with this solution though is that the user address doesnât get updated if I am switching wallet.
Is there something I am missing?
are you using like the latest version of moralis
and react-moralis
?
âmoralisâ: â^0.0.184â,
âreact-moralisâ: â^0.3.11â,
I had other bugs with the latest version using etherjs. So @cryptokid advised me to use the last stable version.
this is from current user object, not from what is in metamask, so it will not get updated when wallet is switched
Ohhh I see, not aware of this issue, also yeah if you use user.get("ethAddress")
the reason why it doesnât change automatically is because it fetches from DB instead of detecting it locally
@cryptokid @YosephKS I know all of what youâre saying. My question is: why sometimes when I refresh my app, the account value is set to null
and never updated again?
maybe it was not updated yet when it tried to display it, how do you display it?
I am using this code inside custom hook:
useEffect(() => {
if (!account) return;
// Do something
}, [account]);
This code is never run because account is always null and never updated
how do you initialize the account on refresh?
Only const {account} = useMoralis();
It should work no?
I donât know, https://github.com/MoralisWeb3/react-moralis#usemoralis
there seem to be a lot of values from useMoralis, like isInitialized, isInitializing, user, enableWeb3, account, isWeb3Enabled
a lot of value yes but it would better if itâs actually working
maybe you need to use enableWeb3, check isInitialized, or isWeb3Enabled
Here what I am doing:
App.tsx
const { isInitialized, Moralis } = useMoralis();
useEffect(() => {
Moralis.Web3.enableWeb3();
}, [Moralis]);
if (!isInitialized) {
return <Loader />;
}
return <Component />
Component.tsx
useEffect(() => {
if (!isAuthenticated) return;
if (!account) return;
// DO STUFF
}, [account, isAuthenticated]);
I am always getting an empty account value with null
if you use console.log(account) on a button, it works?
why with a button? I have tried an it is the same
and btw, isWeb3Enabled is always false, even after calling Moralis.Web3.enableWeb3();
maybe that is why account is also undefined, if web3 is not enabled
So there is a bug because isWeb3Enabled is always false
try something like that, worked for me:
const { isInitialized, account} = useMoralis();
useEffect(() => {
if (isInitialized && account) {
**YOUR CODE HERE**
}
}, [isInitialized, account]);