Error when trying to switch to Avalanch Testnet

Hi,
When trying to switch to the Avalanche Testnet, if it’s not already set up on metamask, I get the following error:

Unhandled Rejection (Error): Chain 0xa869 not supported or is not specified

(anonymous function)

[...]/src/hooks/core/useChain/useChain.ts:16

13 | const chainData = getChain(providedChainId);  
14 |   
15 | if (!chainData) {> 
16 |   throw new Error(     | ^  
17 |     `Chain ${providedChainId} not supported or is not specified`,  
18 |   );  
19 | }

Using Moralis v0.0.184

Yes it is the way it is, you need to add try catch logic to handle the error and make sure to addNetwork if before switching to it :raised_hands:

Hey yes this is by design, on a good note we support switching chains as follows

await Moralis.switchNetwork(chainId); 

Hope this helps

1 Like