Balance returned is always 0 for a local dev server

Hello,

I am using Moralis React and trying to get some basic functionality working. Authentication seems to be working well, but now i’d like to check the ETH balance of the connected wallet.

I followed this tutorial to connect the Moralis instance to my local Ganache chain.

https://docs.moralis.io/guides/deploy-and-track-erc20-events

And i am using the following code which returns 0 ETH in my metamask account.

The user object’s account details appear to have the correct address.

The below code is being used to enableWeb3 and get balances. However, the balance returned is 0 and i have 100ETH (the ganache default) in the account i am using. I have also tried to chaing the chain to the Ganache chainId.

function App() {
  const { isWeb3Enabled, enableWeb3, isAuthenticated, isWeb3EnableLoading, user } =
    useMoralis();
  console.log('User',user);

  const nativeBalance = useNativeBalance({ chain: "eth" });
  console.log(nativeBalance);

  useEffect(() => {
    if (!isWeb3Enabled && isAuthenticated) {
      enableWeb3({ provider: "metamask" });
      console.log("web3 activated");
    }
  }, [isWeb3Enabled, isAuthenticated, enableWeb3]);

  return <div></div>;
}

Any clues as to how to solve this issue?
Does anyone have a working complete boilderplate example of how to use Moralis React?

Update:

After searching on this forum, i found another code snippet. This just returns an empty array.


  useEffect(async () => {
    if (!isWeb3Enabled && isAuthenticated) {
      enableWeb3({ provider: "metamask" });
      console.log("web3 activated");
      console.log("before getTokenBalances");
      let payload_ = {
        chain: "eth",
        address: "MY WALLET ADDRESS",
      };
      let balances_ = await Web3Api.account.getTokenBalances(payload_);
      console.log(balances_);
    }
  }, [isWeb3Enabled, isAuthenticated, enableWeb3]);

Hmmmm…

I also found this…

“web3api calls don’t work with local dev chain, probably that is the problem. It should work on a testnet network.” @cryptokid

So… what is the purpose of the local dev chain setup? If it is not possible to interact with the locally deployed Ganache blockchain. This is very confusing.

yes, web3api calls don’t work with local devchain, you may get some data synced in your Moralis Server db that you could query