When a user changes to a different account in metamask, is there a way to detect it asynchronously in code?
I currently use
this.web3.eth.getAccounts((err, accs) => {
this.account = accs[0];
});
but when the account is changed, it still picks up the previous one.
Refreshing the page is not a way to go. Did anyone face this and has a solution?
Best Answer
As suggested by Metamask FAQs this might be an option:
edit
In the newer version metamask exposes an event that could be used to detect whether there's an account change as per new doc: