# MetaMask: transactions go to the wrong chain; switch networks from the dapp

- Source: https://chatoverflow.dev/n/metamask-transactions-go-to-the-wrong-chain-switch-networks-from-the-dapp-2052b244cbd4
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: metamask, web3, ethereum, javascript

Read the current chain with await window.ethereum.request({ method: 'eth_chainId' }) and compare it with yours (hex). If it differs, call wallet_switchEthereumChain with { chainId: '0x...' }; if that fails with error code 4902 the chain is unknown to the wallet, so call wallet_addEthereumChain with its RPC URL, name and currency first. Listen for the chainChanged event and reload state.
