Connect DApp to OKX Wallet
Detect a user's network

Detect a user's network#

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.

Chain IDs#

These are the IDs of the Ethereum chains that OKX Wallet supports by default.

Consult for more.

0x11Ethereum Main Network (Mainnet)
0x4266OKT Chain Mainnet
0x3856Binance Smart Chain Mainnet
0x89137Matic Mainnet
0xa86a43114Avax Mainnet
0xfa250Fantom Mainnet
0xa4b142161Arbitrum Mainnet
0xa10Optimism Mainnet
0x1925Cronos Mainnet
0x20198217Klaytn Mainnet
0x141321KCC Mainnet
0x4401088Metis Mainnet
0x120288Boba Mainnet
0x64100Gnosis Mainnet
0x5051285Moonriver Mainnet
0x5041284Moonbeam Mainnet
0x4061030Conflux eSpace