(Solved) Formatted always returns null

im using the exact same code as the boilerplate found here(Ethereum Boilerplate)

just to make sure I also deleted moralis and react-moralis then re-installed…

if i console log get token balances like this…

const Refresh = () => {
        getBalances({params: {chain: 'bsc', address: props.address }});
        fetchERC20Balances({ params: { chain: "bsc" }});
        console.log(balance);
    }

it returns the balance with formatted as null but if i try to console log the balance with formatting (balance.formatted) the only thing in the console is null???

nothing other than the fetchERC20Balances works with moralis for me…

any help would be greatly appreciated thank you.

Replace your code with this code, and it should work just fine.

import { useMoralis, useNativeBalance } from "react-moralis";

function NativeBalance(props) {

  const { data: balance } = useNativeBalance(props);

  const { account, isAuthenticated } = useMoralis();

  if (!account || !isAuthenticated) return null;

  return <div style={{ textAlign: "center", whiteSpace: "nowrap" }}>{balance.formatted}</div>;

}

export default NativeBalance;
1 Like

This worked THANK YOU!!

it works thanks a lot for the information