[SOLVED] Getting user's wallet Address only showing original wallet

I’m using React Moralis for a web app in which the user connects their wallet using a web3uikit ConnectButton with moralis auth. I need to know the user’s wallet address based on which account they’re currently using, and using user.get("ethAddress") works, but when I change wallet accounts the following code still prints that I am on the original account that logged in

   const [userAddress, setAddress] = useState("0")


useEffect(() => {
        if (isAuthenticated) {
            setAddress(user!.get("ethAddress").toLowerCase())
            console.log(`user address:  ${userAddress}`)
        }
    }, [isAuthenticated, chainId])

Any idea why this isn’t working? Is there a better way to get/set the current users address?

You can get the connected account from account in

const { account } = useMoralis()

And you can check if the account gotten from above iss connected to the user user?.get("accounts"),

You can wacth account change having such

  useEffect(() => {
    console.log(account);
  }, [account]);
1 Like

Ah, that’s exactly what I needed. Thanks so much!