-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
switchChainAsync
resolves inconsistently with MetaMask chain switch state
#4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What connector are you using? MetaMask, Injected, EIP-6963, etc. |
As specified in the description and code, we are using MetaMask as the connector.
The behavior is consistent in both cases: |
This is an ongoing critical bug, why has this issue been closed? |
Nothing has changed with the
Not reproducible. (It's also not a security issue so not a critical bug as far as we are concerned.) |
Hello @tmm I see the issue was closed as "not reproducible," but the problem is easily observable using the provided example. To clarify further:
Please directly verify the problematic behavior using the reproducible example provided at this link: https://stackblitz.com/edit/new-wagmi-hrpyucft?file=src%2FApp.tsx When you open the browser console after running this example, the problematic behavior becomes evident. Here's exactly what happens during the chain switch: Detailed console log example during the switch from Base (chainId 8453) to Arbitrum (chainId 42161):
The promise ( I'm available for further clarification or additional testing if needed. Thank you. |
Check existing issues
Describe the bug
There is an inconsistency in the behavior of
switchChainAsync
when used with MetaMask. The function resolves before the actual chain switch is completed, leading to a mismatch between the Promise resolution and the actual chain state.Key observations:
Timing:
switchChainAsync
resolves immediately after sending the request to MetaMaskState Management:
useChainId
,useAccount
) maintain previous chain valuesLink to Minimal Reproducible Example
https://stackblitz.com/edit/new-wagmi-hrpyucft?file=src%2FApp.tsx
Steps To Reproduce
Console output showing the issue:
What Wagmi package(s) are you using?
wagmi
Wagmi Package(s) Version(s)
[email protected]
Viem Version
2.24.1
TypeScript Version
5.7.3
Anything else?
Using:
The issue affects the reliability of chain-switching logic in dApps, as developers cannot depend on the Promise resolution to accurately reflect the actual chain state.
The text was updated successfully, but these errors were encountered: