Skip to content

Eliminate polling for wallet account change #2295

@roienatan

Description

@roienatan

Currently we poll every 2000ms for account change in MetaMask.
Instead, we can use a listener for account changes, like this:

window.ethereum.on("accountsChanged", (accounts: Array<any>) => {
  //Handle the new accounts.
  //"accounts" will always be an array, but it can be empty.
  //The current account is at accounts[0]
});

See also https://docs.metamask.io/guide/ethereum-provider.html#events.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions