Skip to Content

Ethereum / EVM

Use the injected EIP-1193 provider to build EVM dApps with OneKey. All EVM-compatible chains (Ethereum, Polygon, BSC, Arbitrum, Optimism, Base, etc.) share the same provider.


Provider Detection

Modern multi-wallet detection that avoids conflicts:

const providers: any[] = [] window.addEventListener('eip6963:announceProvider', (e: any) => { providers.push(e.detail) }) window.dispatchEvent(new Event('eip6963:requestProvider')) // Find OneKey by rdns const onekey = providers.find(p => p.info.rdns === 'so.onekey.app.wallet') const accounts = await onekey.provider.request({ method: 'eth_requestAccounts' })

Direct Access (Fallback)

const provider = window.$onekey?.ethereum if (!provider) throw new Error('OneKey not detected') const accounts = await provider.request({ method: 'eth_requestAccounts' })

Events

// Account changed provider.on('accountsChanged', (accounts) => { console.log('Account:', accounts[0]) }) // Network changed provider.on('chainChanged', (chainId) => { console.log('Chain:', chainId) window.location.reload() // Recommended }) // Connected provider.on('connect', (info) => { console.log('Connected to chain:', info.chainId) })

Error Codes

CodeDescriptionSolution
4001User rejectedHandle rejection gracefully
4902Unknown chainAdd chain with wallet_addEthereumChain
-32602Invalid paramsUse 0x-prefixed hex strings
-32603Internal errorCheck request format

Chain IDs

NetworkChain IDHex
Ethereum Mainnet10x1
Polygon1370x89
BSC560x38
Arbitrum One421610xa4b1
Optimism100xa
Base84530x2105

See chainlist.org  for more chains.

For quick integration with UI components, use RainbowKit or Web3Modal.

Last updated on