For Ethereum chain development, it's important to keep track of a user's network chain ID, as all RPC requests are submitted to the currently connected network.
Use the eth_chainId
RPC method to detect the chain ID of a user's current network. Listen to the chainChanged
provider event to detect when the user changes networks.
As an example, the following code is used to detect a user's network and when the user changes networks:
const chainId = await window.ethereum.request({ method: 'eth_chainId' });
window.ethereum.on('chainChanged', handleChainChanged);
function handleChainChanged(chainId) {
// We recommend reloading the page, unless you must do otherwise.
window.location.reload();
}
These are the IDs of the Ethereum chains that OKX Wallet supports by default.
Consult chainid.network for more.
Hex | Decimal | Network |
---|---|---|
0x1 | 1 | Ethereum Main Network (Mainnet) |
0x2711 | 10001 | ETHW |
0x42 | 66 | OKT Chain Mainnet |
0x38 | 56 | Binance Smart Chain Mainnet |
0x89 | 137 | Matic Mainnet |
0xa86a | 43114 | Avax Mainnet |
0xfa | 250 | Fantom Mainnet |
0xa4b1 | 42161 | Arbitrum Mainnet |
0xa | 10 | Optimism Mainnet |
0x19 | 25 | Cronos Mainnet |
0x2019 | 8217 | Klaytn Mainnet |
0x141 | 321 | KCC Mainnet |
0x440 | 1088 | Metis Mainnet |
0x120 | 288 | Boba Mainnet |
0x64 | 100 | Gnosis Mainnet |
0x505 | 1285 | Moonriver Mainnet |
0x504 | 1284 | Moonbeam Mainnet |
0x406 | 1030 | Conflux eSpace |