requestAccounts()

Feature
Requests user permission for the dApp to access their accounts.

Parameters

(none)

Return Value

Promise<string[]>

example

// Triggers the wallet connection popup if the dApp is not yet connected.
// Returns all accounts the user has permitted this site to access.
async function connect() {
  try {
    const accounts = await provider.requestAccounts();
    console.log('Permitted accounts:', accounts);
    
    // The first account in the array is typically the user's "selected" account.
    const selected = accounts[0]; 
  } catch (error) {
    // User rejected the request
    console.error(error.message);
  }
}

Last updated