Skip to main content

eth_accounts

Read the list of authorized accounts for the current DApp. This method only queries the existing connection status and does not pop up the wallet authorization window.


Inputs

none


return value

string[] - ​​Array of authorized account addresses; if not connected yet, returns an empty array.


Demo

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

if (accounts.length > 0) {
console.log("Authorized account:", accounts[0]);
} else {
console.log("Wallet connection is missing");
}

Check connection status when page loads

async function loadAuthorizedAccount() {
const accounts = await window.$ukey.ethereum.request({
method: "eth_accounts",
});
return accounts.length > 0 ? accounts[0] : null;
}

const account = await loadAuthorizedAccount();
if (account) {
console.log("Connection established:", account);
} else {
// Note: Requires user connection
await window.$ukey.ethereum.request({
method: "eth_requestAccounts",
});
}

error code

CodeMessageDetails
-32603Provider internal failureInternal failure inside the provider

illustrate

  • The connection pop-up window will not be triggered and is suitable for silent status checking.
  • If an empty array is returned, the user needs to actively click and then call eth_requestAccounts.
  • When switching accounts or disconnecting authorization, please synchronize the page status through the accountsChanged event.