Skip to main content

eth_requestAccounts

Request the user to authorize the current DApp to access the account. It is the main entrance to connect to the wallet. The first call will open the UKey Wallet connection confirmation interface.


Inputs

none


return value

string[] - ​​Array of account addresses after user authorization.


Demo

const accounts = await window.$ukey.ethereum.request({
method: "eth_requestAccounts",
});

console.log("Authorized account:", accounts[0]);

Connect button example

async function requestWalletAccess() {
try {
const accounts = await window.$ukey.ethereum.request({
method: "eth_requestAccounts",
});
console.log("Connection established:", accounts[0]);
return accounts[0];
} catch (error) {
if (error.code === 4001) {
console.log("The user declined the connection");
} else {
console.error("Unable to connect:", error);
}
throw error;
}
}

error code

CodeMessageDetails
4001User rejected the requestConnection approval was rejected by the user
-32002Request already pendingThere is a pending connection request

illustrate

  • It should be called after the user clicks the connect button, and should not automatically pop up when the page loads.
  • If the user has been authorized, the method will directly return the account address.
  • When an existing connection request is not completed, calling again may return -32002.
  • The connection status may still be valid after page refresh, please use eth_accounts to check silently.
  • Follows EIP-1102 specification.