A chainChanged event should invalidate every object that was prepared for the previous chain. Updating a network badge while retaining the old quote is insufficient.
EIP-1193 specifies chainChanged with a hexadecimal chain ID. Normalize that value once into the application's chain identity. Do not compare the string 0x38 directly with the decimal string 56 and conclude they describe different networks.
What to reset
- Active price and executable quote.
- Balance, token metadata and allowance reads for the selected chain.
- Simulation results and prepared wallet request.
- Provider-specific native-token mapping and contract configuration.
A submitted transaction is different: preserve its original chain and hash in history. Switching the wallet to another network does not move the transaction or make it disappear. Its tracking RPC should remain bound to the original chain.
Close the asynchronous gap
Increment a context generation whenever the chain changes. Every asynchronous operation captures the generation when it starts and checks it before committing its result. Aborting an HTTP request helps save work, but a response that already completed still needs this logical guard.
For example, a quote starts on chain A, the wallet changes to B, and the quote for A arrives after the new balance. The generation check rejects that quote even if both chains happen to use identical token address strings.
Recheck eth_chainId immediately before invoking a write. This narrows the interval between rendering the review screen and opening the wallet. If it no longer matches, return to network selection and rebuild the trade. Do not rewrite the chain field on the old transaction; its destination and calldata may encode assumptions from the previous network.
Sources & verification (1)
Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.
- EIP-1193: Ethereum Provider JavaScript API
Account/chain events and user rejection error
https://eips.ethereum.org/EIPS/eip-1193