Detecting Metamask account or network change in Javascript using Web3 1.2.4–2020

source from METAMASK

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 )

Buy me a coffee, Thanks :

Ether : 0xf2d15dEAf62b8c4AFC0343006579E8E662c120D9
Bitcoin : 332UiyAfSXyvhqCYgDgBkNLFSf25ccNV9i
**Do CLAP, COMMENT and SHARE! I also welcome any business opportunities that arises**

--

--

胡家維 Hu Kenneth
Singapore Blockchain-Dapps

撰寫任何事情,O型水瓶混魔羯,咖啡愛好者,Full stack/blockchain Web3 developer,Founder of Blockchain&Dapps meetup ,Udemy teacher。 My Linktree: https://linktr.ee/kennethhutw