Detecting Metamask account or network change in Javascript using Web3 1.2.4–2020
Published in
Oct 21, 2020
A common issue in developing dApps is detecting which account within Metamask a user plans on using. In old way, it is to suggest you to poll every 100 milliseconds.
web3.eth.accounts[0];
var accountInterval = setInterval(function() {
if (web3.eth.accounts[0] !== account) {
account = web3.eth.accounts[0];
updateInterface();
}
}, 100);
Instead, I found the new way to detect Metamask account or Network change in Javascript using Web3.js 1.2.4
I do this because I love it, but if you want me to buy me a cup of coffee I won’t say no :O )