Tracking Netwroks - Avalanche error

And please share your logs/messages.

Also check your chain settings in the metamask

Now it is telling me my wallet is not installed, but i get right chain id now (when i change network)
Do i share logs from console or dashboard ?

Sorry, my bad. In your case you need to use await Moralis.isMetaMaskInstalled();
Instead of const isWeb3Active = Moralis.ensureWeb3IsInstalled()

1 Like

Now it seems it is working thanks for help :star_struck: !

1 Like

You are welcome! Happy BUIDLing :man_mechanic:

1 Like

One question.

1. What do you get back if you connect to a moralis website with avax chain and write in console chainID = await Moralis.getChainId(); . I get back 1. This is very problematic, because when user logs in I get and compute everything for eth chain (cus 1 is returned before). For all other chains work perfectly.

  1. And also why does this
Moralis.onChainChanged(function(chain){
        currentChain = chian;
})

return completly different chian id than chainID = await Moralis.getChainId(); (it returns same chain but with different naming -> 1 and 0x1) ?

1 is decimal format
0x1 is hex format

1 Like

If i use Moralis.getChainId() on Avalance I get 1 too. I don’t know why :sweat_smile:

Okay, I also found the difficulty that if you want to use .getChainId you need to enable web3.
I suggest you to use the classic way in your case:

if (window.ethereum) {
   const chainId = window.ethereum.chainId;
}

The method will return you chainId in hex format 0xa86a

1 Like

Now it is fully working. Thanks again !

1 Like

Happy to help :man_factory_worker:

1 Like

the function switchNetwork() eth to avax doesn’t work for me .but the other chains work.

Hey @ihxx

Please for each question open a new topic :raised_hands:
But I guess we can easy solve your problem:

Moralis.switchNetwork("0xa86a") works nice, I just tested it. If your Metamask doesn’t have avalanche it will not switch to it. You need to add it manually.

Take a look at https://docs.moralis.io/moralis-server/web3/web3#addnetwork

1 Like

getChainId() worked properly for avalanche past couple of days. but today all of a sudden, it started returning 1 … Please kindly take a look. This kind of bug is a bit scary … thank you

maybe MetaMask is connected to ETH network? I tested now few networks and it looks like it works fine.

getChainId() works for all networks besides avalanche. Please kindly take a look at the other users’ messages, too. We all have the same issue. getChainId() returns 1 for avalanche. thank you

Hey @junkseeker

It’s a known buggy behavior of Web3.js which we use in our Moralis library

1 Like

We will notify when we will find a solution for this and add it to the library :raised_hands:

It really depends from which chain are you switching to avalanche

from which chain are you switching?

you can try to use id = await web3.eth.getChainId() for now