fix: handle ethers.js wrapped 4902 error for Base Sepolia chain switch#25
Merged
fix: handle ethers.js wrapped 4902 error for Base Sepolia chain switch#25
Conversation
- Add isChainNotAddedError() helper to detect 4902 in raw, wrapped, and message forms - On 4902, call wallet_addEthereumChain with full chain params instead of throwing - Add EVM_CHAIN_PARAMS config for Base Sepolia (RPC, explorer, native currency) - Hide testnet chains by default; show only when ?test=true is set - Add 9 new evm.test.ts tests covering all 4902 detection patterns - Update page.test.tsx to verify testnet visibility logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UNKNOWN_ERRORwithdata.originalError.codewallet_addEthereumChainfallback so the wallet automatically adds Base Sepolia when missing?test=trueis setChanges
web/src/lib/wallets/evm.tsisChainNotAddedError()helper that checks three patterns: rawcode === 4902, ethers-wrappeddata.originalError.code === 4902, and message string fallbackwallet_addEthereumChainwith chain params instead of throwingweb/src/lib/config.tsEVM_CHAIN_PARAMSmap with full Base Sepolia config (RPC URL, block explorer, native currency)web/src/app/pay/page.tsx?test=truefrom URL; filter chains to hidetestnet: trueentries by defaultTests
web/src/__tests__/lib/evm.test.ts— 9 tests coveringisEvmAvailable, raw 4902, ethers-wrapped 4902, message-based fallback, missing chain params, non-4902 re-throw, no-provider errorpage.test.tsx— testnet visibility assertions (hidden by default, shown with?test=true)Test Results