Error when calling web3Auth.switchChain: “TypeError: l is not a function”

Hi, I’m running into an issue when trying to switch chains using web3Auth.switchChain, but it seems to happen only when using the MetaMask browser extension, and only with the Arbitrum Sepolia testnet.

const switchChain = async (chain: CustomChainConfig) => {
  if (!provider) {
    logConsole('switchChain. provider not initialized yet')
    return
  }

  if (!web3Auth) {
    logConsole('switchChain. web3auth not initialized yet')
    return ''
  }

  await web3Auth.addChain(chain)
  await web3Auth.switchChain({ chainId: chain.chainId })
}

The chain config I’m trying to use is:

ArbitrumSepolia: {
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  chainId: '0x66eee',
  displayName: 'Arbitrum Sepolia',
  tickerName: 'ETH',
  ticker: 'ETH',
  rpcTarget: 'https://sepolia-rollup.arbitrum.io/rpc',
  logo: '',
  blockExplorerUrl: 'https://sepolia-explorer.arbitrum.io',
  isTestnet: true
}

And here’s the error I’m getting:

{
  "code": -32603,
  "message": "l is not a function",
  "data": {
    "cause": {
      "stack": "TypeError: l is not a function\n  at n.switchChain (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:67870)\n  at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:61494",
      "message": "l is not a function"
    }
  }
}

Here are the Web3Auth SDK versions I’m using:

"@web3auth/auth-adapter": "^9.7.0",
"@web3auth/base": "^9.7.0",
"@web3auth/default-evm-adapter": "^9.7.0",
"@web3auth/ethereum-provider": "^9.7.0",
"@web3auth/no-modal": "^9.7.0",
"@web3auth/wallet-connect-v2-adapter": "^9.7.0"

Has anyone run into this before?

Hi Felipe,

Thanks for reaching out with your detailed issue description. It looks like you are encountering a TypeError when attempting to switch chains with the MetaMask browser extension, specifically for the Arbitrum Sepolia testnet. This is very helpful information for us!

From your message, you’ve provided key details such as:

  • SDK Details: Using Web3Auth Plug n Play with several adapters and providers.
  • SDK Version: All set to ^9.7.0.
  • Platform: Specifically encountering the error with the MetaMask browser extension.

The error message indicates that a function, likely involved in the switchChain call, is not being recognized. Here are a few things you might want to check or try:

  1. Compatibility Issue: Ensure that the MetaMask extension you are using supports switching to custom RPCs like Arbitrum Sepolia. Sometimes, certain functions may not be available in test environments.

  2. Chain ID Format: Double-check that the chainId field is correct ('0x66eee' matches the Arbitrum Sepolia testnet properly in your configuration).

  3. Web3Auth Documentation: Review the Web3Auth documentation for chain switching to ensure that there are no additional steps required or compatibility issues.

  4. MetaMask Forums: Consider checking if this specific issue is a known bug or behavior in MetaMask when interacting with testnets like Arbitrum Sepolia.

If you’ve gone through these points and the issue persists, please let us know. We might need to dive deeper, possibly with a broader error tracing or exploring updates/bugs within MetaMask itself.

Feel free to share any additional screenshots or logs that may help further diagnose the problem. I’m here to assist!

Best,
[Your Name]

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours

  1. MetaMask does support Arbitrum Sepolia. I’ve tested it here: MetaMask developer documentation
  2. The Chain ID is correct: Arbitrum Sepolia RPC and Chain settings | ChainList
  3. This page does not exist

I just noticed this also happens on mainnet when switching to Arbitrum One . Other networks like Ethereum Sepolia seem to work fine.

These are the RPCs I’m using:
L1 testnet: https://eth-sepolia.g.alchemy.com/v2/{key}
L2 testnet: https://sepolia-rollup.arbitrum.io/rpc

L1 mainnet: https://eth-mainnet.g.alchemy.com/v2/{key}
L2 mainnet: https://arb1.arbitrum.io/rpc

I found out that the error is actually happening during the addChain call, not the switchChain. Here’s the configuration I’m using:

const arbitrumSepolia: CustomChainConfig = {
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  chainId: '0x66eee',
  displayName: 'Arbitrum Sepolia',
  tickerName: 'ETH',
  ticker: 'ETH',
  rpcTarget: 'https://sepolia-rollup.arbitrum.io/rpc',
  logo: '',
  blockExplorerUrl: 'https://sepolia-explorer.arbitrum.io',
  isTestnet: true
}

await web3Auth.addChain(arbitrumSepolia)

Error:

{
    "code": -32603,
    "message": "h is not a function",
    "data": {
        "cause": {
            "stack": "TypeError: h is not a function\n  at r.switchChain (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:358033)\n  at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:91674",
            "message": "h is not a function"
        }
    }
}

The error seems to occur when calling web3Auth.addChain(chain). Any ideas on what might be causing this?

Does anyone have any updates?

I’ll mark this as resolved. This seems to be an issue with MetaMask: [Bug]: wallet_addEthereumChain succeeds in ui but throws TypeError(l is not a function) in MetaMask 12.14.2 · Issue #31464 · MetaMask/metamask-extension · GitHub

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.