Skip to main content

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

CodeDescriptionRecommended handling
4001User rejected the requestKeep the flow retryable and let users try again
4902Chain is not recognizedPrompt the user to add the network with wallet_addEthereumChain
-32602Malformed request dataVerify the hex prefix, address, and parameter order
-32603Provider internal failureVerify the current network, request format, and wallet state

Chain ID

NetworkChain IDHex
Ethereum mainnet10x1
Polygon1370x89
BSC560x38
Arbitrum One421610xa4b1
Optimism100xa
Base84530x2105

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.