Ethereum / EVM
UKey Wallet will provide an EIP-1193 compliant Ethereum Provider in the browser. DApp can complete account connection, chain switching, message signing and transaction sending through this Provider. EVM-compatible chains such as Ethereum, Polygon, BSC, Arbitrum, Optimism, and Base all use the same calling method.
Provider detection
EIP-6963 (preferred)
In a browser environment where multiple wallets coexist, use EIP-6963 to discover wallets. In this way, users can clearly choose UKey Wallet and avoid misconnection caused by window.ethereum being covered by other wallets.
const providers: any[] = [];
window.addEventListener("eip6963:announceProvider", (e: any) => {
providers.push(e.detail);
});
window.dispatchEvent(new Event("eip6963:requestProvider"));
// Note: Find UKey Wallet via rdns
const ukey = providers.find((p) => p.info.rdns === "so.ukey.app.wallet");
const accounts = await ukey.provider.request({
method: "eth_requestAccounts",
});
Direct access (fallback solution)
If the project is not yet connected to EIP-6963, you can read UKey Wallet's dedicated injection object as a fallback solution:
const provider = window.$ukey?.ethereum;
if (!provider) throw new Error("UKey Wallet not detected");
const accounts = await provider.request({ method: "eth_requestAccounts" });
displayed_sidebar: softwareSidebar
Common events
Providers trigger events when account, network, and connection status changes. Applications should refresh local state based on events and do not rely on polling.
// Note: Account changes
provider.on("accountsChanged", (accounts) => {
console.log("Selected account:", accounts[0]);
});
// Note: Network changes
provider.on("chainChanged", (chainId) => {
console.log("Current chain:", chainId);
window.location.reload(); // Note: recommend
});
// Note: Connected
provider.on("connect", (info) => {
console.log("Chain connection established:", info.chainId);
});
error code
| Code | Description | Recommended handling |
|---|---|---|
| 4001 | User rejected the request | Keep the flow retryable and let users try again |
| 4902 | Chain is not recognized | Prompt the user to add the network with wallet_addEthereumChain |
| -32602 | Malformed request data | Verify the hex prefix, address, and parameter order |
| -32603 | Provider internal failure | Verify the current network, request format, and wallet state |
Chain ID
| Network | Chain ID | Hex |
|---|---|---|
| Ethereum mainnet | 1 | 0x1 |
| Polygon | 137 | 0x89 |
| BSC | 56 | 0x38 |
| Arbitrum One | 42161 | 0xa4b1 |
| Optimism | 10 | 0xa |
| Base | 8453 | 0x2105 |
For more network inputs, please refer to chainlist.org. Before initiating a chain switch or add chain request, please confirm that RPC, block explorer, and native coin information come from trusted sources.
If you want to use the connection popup directly, you can start at RainbowKit or Web3Modal.