Disconnect event triggered right after adding or switching to a custom network (MetaMask 13.7.0 + Web3Auth + wagmi + Next.js)

Hi 조성혁 — thanks for the clear report. I can see you’re reporting an issue (disconnect event) after adding/switching a custom network while using MetaMask Embedded Wallets (Web3Auth) + wagmi in a Next.js app. I’ve summarized what you provided, suggested quick checks/workarounds, and listed only the additional details the support team will likely need to investigate.

Summary of provided details

  • SDK / integration: MetaMask Embedded Wallets (Web3Auth)
  • MetaMask Extension version: 13.7.0
  • Framework / platform: Next.js (browser: Chrome 142.0.7444.60)
  • Additional libs: wagmi + Web3Auth (example repo: web3auth-examples/quick-starts/nextjs-quick-start at main · Web3Auth/web3auth-examples · GitHub)
  • Change made to example: only replaced clientId with your Web3Auth project ID
  • Repro steps (as provided): connect → call wallet_addEthereumChain / wallet_switchEthereumChain → immediately receives a ‘disconnect’ event (wagmi/Web3Auth go to disconnected)
  • Expected: network switch should not cause disconnect
  • Actual: MetaMask emits ‘disconnect’ immediately after chain add/switch; manual reconnect required

Missing or useful extra info (please share if convenient)

  • Web3Auth SDK version (e.g. @web3auth/web3auth version)
  • wagmi version (and ethers or other provider libs versions if used)
  • Code snippets showing how you initialize Web3Auth / MetaMask Embedded and how you call connect (initialization & login snippets). If you already used the example unmodified other than clientId, indicate that explicitly.
  • Browser console logs captured while reproducing (the console output immediately before/during/after the network switch). A screenshot or copy/paste of the errors is fine — these logs are often the fastest way for the team to locate the cause.

Why we ask for the above

  • Versions of Web3Auth / wagmi are often necessary to reproduce environment-specific behavior. Console logs can show internal errors or provider messages that explain why the provider emitted ‘disconnect’. The init/login snippet confirms whether the embedded provider is being re-initialized or replaced when chain switching occurs.

Quick troubleshooting steps & possible workarounds you can try now

  1. Isolate: attempt the same flow with a plain MetaMask extension (no Web3Auth/wagmi) to check if the extension itself emits disconnect on your machine. If it does not, the issue is likely in the Web3Auth/wagmi flow.
  2. Try a different MetaMask version (or update to the latest if available) and/or a different browser profile to rule out a local regression or extension conflict.
  3. Watch provider events in the console. Add temporary listeners in your app to log events:
    • provider.on(‘chainChanged’, …)
    • provider.on(‘accountsChanged’, …)
    • provider.on(‘disconnect’, …)
      Capture the order of events when you call wallet_addEthereumChain / wallet_switchEthereumChain.
  4. Short-term app workaround: if you must support the flow immediately, handle disconnect by detecting if it coincides with a chainChanged event and automatically attempt to re-connect (call wagmi connect()) rather than treating it as a full user-initiated disconnect. This is a workaround while we validate whether this is an underlying provider bug.

Relevant docs (for quick reference)

If you’d like escalation to the engineering team, please attach the missing items above (especially the Web3Auth/wagmi versions, init/login snippets, and console logs). With those, I’ll file this for deeper investigation and tag the product engineers. If you prefer, paste the console log here and I’ll take a first pass at it.

Would you like me to escalate now, or do you want to paste the small snippets/logs first so I can try a targeted suggestion?

Note: This response was generated by an AI bot and may require further verification. The MetaMask Community 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. MetaMask Developer Office Hours