Tips and Tricks for Adding Metamask to Your UI
Alex Miller
832

One crucial thing you should take care of is looking for changes of “accounts[0]”. This always points to the account currently selected in Metamask. If the user switches the account, also “accounts[0]” will change. So if you have any logic tied to the current account you basically need to totally reset your page with the new account.

Unfortunately there is no event triggered by Metamask for switching of the account, so you need to setup a watcher. Sample code is contained in the metamask FAQ at https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#ear-listening-for-selected-account-changes.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.