You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to use switchChain to align the user’s Metamask wallet chain with the required Sepolia test network (chain ID: 11155111), various issues occur. These issues arise during initial wallet connection, subsequent chain changes initiated on the user’s phone, and while performing contract interactions. Occasionally, the native Switch chain modal from reown appears or fails unexpectedly, leading to user confusion and disrupted workflows. Below are the detailed scenarios:
The Switch chain modal is the native UI modal from reown. Scenario 1: Connecting Wallet on an Incorrect Chain
Steps:
The user opens the application while their Metamask is on an incorrect chain (e.g., Ethereum Mainnet).
Upon connecting, the app prompts the user to switch to the correct chain (Sepolia).
Occasionally, after confirming the switch, the chain does successfully switch in Metamask.
Issue:
Despite the chain successfully switching in Metamask, the native Switch chain modal displays an error:
Switch declined, switch can be declined if chain is not supported by a wallet previous request still active
It then offers a "try again" option. Selecting "try again" closes the modal, but this step is unnecessary and confusing since the chain is already switched.
2024-12-17.19.50.30.mov
Expected Behavior:
No error should appear if the chain switch is successful. The modal should close automatically without prompting to "try again."
Scenario 2: Changing to an Incorrect Chain After Initial Correct Connection
Steps:
The user initially connects their wallet on the correct chain (Sepolia).
On their phone, they manually switch the wallet’s chain to an incorrect one (e.g., Ethereum Mainnet).
The Switch chain modal appears, prompting the user to switch back to Sepolia.
Issue:
When the user selects Sepolia in the modal, the modal closes but does not actually trigger the chain switch in Metamask. The chain remains on the incorrect network, leaving the user stuck on the wrong chain.
2024-12-17.20.04.05.mov
Expected Behavior:
Selecting the correct chain (Sepolia) in the modal should actively switch the chain in Metamask rather than just closing the modal.
Scenario 3: Performing Contract Actions on an Incorrect Chain
Steps:
The user is connected to their wallet but is currently on an incorrect chain.
The user attempts a contract interaction (e.g., readContract or writeContract).
The application prompts the user to switch to the correct chain.
The user agrees to switch chains.
Issue:
After agreeing to switch, an error occurs:
{ ..., code: 4001, message: "User rejected the request." }
This can happen if the user previously switched the chain manually outside the app (similar to Scenario 2), causing the chain switching logic to fail or become confused.
Expected Behavior:
If the user agrees to switch, the chain should switch correctly, and the contract call should proceed without a "User rejected" error message.
Scenario 4: Spontaneous Appearance of the Switch chain Modal
Behavior: Without any user action (such as navigating, switching chains manually, or performing contract actions), the Switch chain modal sometimes appears on its own, even when the wallet is already on the correct chain.
Issue: This unexpected prompt is both confusing and disruptive. It’s not clear what triggers it, and since the chain is already correct, it should not appear at all.
Expected Behavior:
The Switch chain modal should only appear when the wallet’s current chain does not match the required chain and should not randomly pop up otherwise.
I’ve recorded videos demonstrating these issues (though they are local), but you can reproduce the behavior here: AppKit Lab (Wagmi)
I am happy to provide more details about my setup and even prepare a small demo if that would be helpful.
Link to minimal reproducible example
https://appkit-lab.reown.com/library/wagmi/
Summary
When attempting to use switchChain to align the user’s Metamask wallet chain with the required Sepolia test network (chain ID: 11155111), various issues occur. These issues arise during initial wallet connection, subsequent chain changes initiated on the user’s phone, and while performing contract interactions. Occasionally, the native Switch chain modal from reown appears or fails unexpectedly, leading to user confusion and disrupted workflows. Below are the detailed scenarios:
Safari PC: 18.1.1 (20619.2.8.11.12)
Metamask 7.37.0
Details & Scenarios
Context:
Scenario 1: Connecting Wallet on an Incorrect Chain
Despite the chain successfully switching in Metamask, the native Switch chain modal displays an error:
It then offers a "try again" option. Selecting "try again" closes the modal, but this step is unnecessary and confusing since the chain is already switched.
2024-12-17.19.50.30.mov
Expected Behavior:
No error should appear if the chain switch is successful. The modal should close automatically without prompting to "try again."
Scenario 2: Changing to an Incorrect Chain After Initial Correct Connection
Steps:
When the user selects Sepolia in the modal, the modal closes but does not actually trigger the chain switch in Metamask. The chain remains on the incorrect network, leaving the user stuck on the wrong chain.
2024-12-17.20.04.05.mov
Expected Behavior:
Selecting the correct chain (Sepolia) in the modal should actively switch the chain in Metamask rather than just closing the modal.
Scenario 3: Performing Contract Actions on an Incorrect Chain
After agreeing to switch, an error occurs:
This can happen if the user previously switched the chain manually outside the app (similar to Scenario 2), causing the chain switching logic to fail or become confused.
Expected Behavior:
If the user agrees to switch, the chain should switch correctly, and the contract call should proceed without a "User rejected" error message.
Scenario 4: Spontaneous Appearance of the Switch chain Modal
Expected Behavior:
The Switch chain modal should only appear when the wallet’s current chain does not match the required chain and should not randomly pop up otherwise.
I’ve recorded videos demonstrating these issues (though they are local), but you can reproduce the behavior here:
AppKit Lab (Wagmi)
I am happy to provide more details about my setup and even prepare a small demo if that would be helpful.
List of related npm package versions
Node.js Version
v20.17.0
Package Manager
10.8.2
The text was updated successfully, but these errors were encountered: