Skip to content

Commit

Permalink
Update eth_accounts return behavior (MetaMask#773)
Browse files Browse the repository at this point in the history
* Update eth_accounts return behavior

* minor edits

* small change

* Update wallet/reference/provider-api.md

---------

Co-authored-by: Alexandra Tran <[email protected]>
Co-authored-by: Alexandra Tran Carrillo <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2023
1 parent 3cccec7 commit 6c1dc66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
14 changes: 3 additions & 11 deletions wallet/get-started/access-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ seamless connection from your dapp to a MetaMask wallet client.
## Create a connect button

We recommend providing a button to allow users to connect MetaMask to your dapp.
Selecting this button should call `eth_requestAccounts` to access the user's account.
Selecting this button should call `eth_requestAccounts` to access the user's accounts.

In the [example project code](set-up-dev-environment.md#example), the following JavaScript code
accesses the user's accounts when they select a connect button, and the following HTML code
Expand Down Expand Up @@ -79,14 +79,6 @@ async function getAccount() {

<!--/tabs-->

:::note
MetaMask currently returns at most one account in the `accounts` array.
The array may contain more than one account in the future.

To retrieve the full list of accounts for which the user has permitted access, use the
[`wallet_getPermissions`](../reference/rpc-api.md#wallet_getpermissions) RPC method.
:::

## Handle accounts

Use the [`eth_accounts`](https://metamask.github.io/api-playground/api-documentation/#eth_accounts)
Expand Down Expand Up @@ -128,7 +120,7 @@ function handleAccountsChanged(accounts) {
```

:::note
MetaMask currently returns at most one account in the `accounts` array.
The array may contain more than one account in the future.
`eth_accounts` now returns the full list of accounts for which the user has permitted access to.
Previously, `eth_accounts` returned at most one account in the `accounts` array.
The first account in the array will always be considered the user's "selected" account.
:::
4 changes: 2 additions & 2 deletions wallet/reference/provider-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ window.ethereum.on('accountsChanged', handler: (accounts: Array<string>) => void
The provider emits this event when the return value of the
[`eth_accounts`](https://metamask.github.io/api-playground/api-documentation/#eth_accounts) RPC
method changes.
`eth_accounts` returns either an empty array, or an array that contains the address of the most
recently used account the caller is permitted to access.
`eth_accounts` returns either an empty array, or an array that contains the addresses of the accounts
the caller is permitted to access with the most recently used account first.
Callers are identified by their URL origin, which means that all sites with the same origin share
the same permissions.

Expand Down

0 comments on commit 6c1dc66

Please sign in to comment.