eth_accounts
Returns the list of accounts that the user has previously connected. This allows your dApp to check if a user is already connected on page load without prompting them to authenticate again. Unlike eth_requestAccounts, this method never shows a modal.
Try it
Parameters
None.
Returns
string[] - Array of account addresses. Returns an empty array if not connected.
Example
const accounts = await provider.request({ method: 'eth_accounts' });
if (accounts.length > 0) {
console.log('Connected as:', accounts[0]);
} else {
console.log('Not connected');
}Notes
- Returns addresses from localStorage if the user has previously connected
- Does not prompt the user to connect - use
eth_requestAccountsfor that - Always returns an array (empty if not connected)