Get the Metamask account balance in usd

I can get the eth balance of the metamsk in eth using this

  async function getBalance(){
    const x = await web3.eth?.getBalance(user?.get("ethAddress"))
    console.log(x)
   }

Is there away to convert this to usd using moralis without using a 3rd party API?

you can use Moralis.Web3API.token.getTokenPrice to the the price of the native currency, you will have to use the version with wrapper eth or wrapped bnb for example.

1 Like