I am trying to listen to the 'chainChanged' event for Metamask, but the event never fires. When running the following snippet, the I get a console.log of the chainId once, but the chainChanged event never runs. What could be the issue? Thanks!

if (window.ethereum) {
        .catch((err: any) => console.error(err));

    window.ethereum.on('chainChanged', handleChainChanged);

    window.ethereum.autoRefreshOnNetworkChange = false;

function handleChainChanged(chainId: number) {

Try window.ethereum.on('networkChanged', handleChainChanged)

From what I know, the new MetaMask api (which will change this command to 'chainChanged') is not yet live.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.