I cannot get the address and its balance even if I connected to the Metamask

93 views Asked by At

I am working on a dapp and I have a problem. The problem is that even if I connected the Metamask to the dapp, I cannot get its balance. But, the most interesting part, I cannot see the address which is connected. I used moralis and ethers in the dapp. This is the code for balance:

const getBalance = async () => {
    const provider = await connectBlockchain()
    const balance = await provider.getBalance(STAKING_CONTRACT_ADDRESS)
    const balanceInEth = ethers.utils.formatEther(balance)
    const finalBalance = (+balanceInEth).toFixed(4)
    setWalletBalance(finalBalance)
  }

 useEffect(() => {
    getBalance()
  }, [getBalance])

In this code account returns null

const { account } = useMoralis()
  console.log(account)

Thanks in advance

0

There are 0 answers