getAccounts()

Feature
Returns the list of accounts this dApp is already permitted to access.

Parameters

(none)

Return Value

Promise<string[]>

example

// Use this on page load to check if the user is already connected.
// This method does *not* trigger a wallet popup.
async function checkConnection() {
  try {
    const accounts = await provider.getAccounts();
    
    if (accounts.length > 0) {
      console.log('User is already connected with:', accounts);
    } else {
      console.log('User is not connected.');
    }
  } catch (error) {
    console.error(error.message);
  }
}

Last updated