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
Hello There!
When I try to switch network with "wallet_switchEthereumChain" I got this error -32603 telling me that the chainId is not recognised, I have double checked and everything seems good on my code the chain id for "Base sepolia" is correct so I don't know why I got this error. Thanks!
The code where the error come from :
switchNetwork: () => Promise<void>
} {
const { provider, chainId } = useWalletData()
const switchNetwork = useCallback(async () => {
if ((provider == null) || !chainId) {
console.log('Provider or chainId is missing')
return
}
console.log('Attempting to switch network to:', `0x${Number(ChainId.SEPOLIA).toString(16)}`)
try {
await window.ethereum?.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: `0x${Number(ChainId.SEPOLIA).toString(16)}` }]
})
console.log('Network switched successfully')
} catch (switchError: any) {
console.log('Error switching network:', switchError)
// This error code indicates that the chain has not been added to MetaMask
if (switchError.code === 4902) {
console.log('Chain not found. Adding new chain...')
try {
await window.ethereum?.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: `0x${Number(ChainId.SEPOLIA).toString(16)}`,
rpcUrls: ['https://base-sepolia-rpc.publicnode.com'],
chainName: 'Base sepolia',
nativeCurrency: {
name: 'ETH',
symbol: 'ETH',
decimals: 18
},
blockExplorerUrls: ['https://explorer-sepolia.etherscan.io']
}]
})
console.log('New chain added successfully')
} catch (addError: any) {
console.error('Error adding new chain:', addError)
}
}
}
}, [provider, chainId]) ```
### Scenario
_No response_
### Design
_No response_
### Technical Details
_No response_
### Threat Modeling Framework
_No response_
### Acceptance Criteria
_No response_
### Stakeholder review needed before the work gets merged
- [ ] Engineering (needed in most cases)
- [ ] Design
- [ ] Product
- [ ] QA (automation tests are required to pass before merging PRs but not all changes are covered by automation tests - please review if QA is needed beyond automation tests)
- [ ] Security
- [ ] Legal
- [ ] Marketing
- [ ] Management (please specify)
- [ ] Other (please specify)
### References
_No response_
The text was updated successfully, but these errors were encountered:
What is this about?
Hello There!
When I try to switch network with "wallet_switchEthereumChain" I got this error -32603 telling me that the chainId is not recognised, I have double checked and everything seems good on my code the chain id for "Base sepolia" is correct so I don't know why I got this error. Thanks!
The code where the error come from :
The text was updated successfully, but these errors were encountered: