Answers for "check web3 metamask disconnect"

0

check web3 metamask disconnect

// The following code snippet is in React
// but you can use the window.ethereum.on("accountsChanged") event 
// in regular JavaScript

// Note: I believe window.ethereum is only available if using Metamask 
// as your web3 provider

useEffect(() => {
    window.ethereum.on("accountsChanged", accounts => {
      if (accounts.length > 0) setAccount(accounts[0]);
      else setAccount("");
    });
}, []);
Posted by: Guest on June-05-2021
0

check web3 metamask disconnect

// The following code snippet is in React
// but you can use the window.ethereum.on("accountsChanged") event 
// in regular JavaScript

// Note: I believe window.ethereum is only available if using Metamask 
// as your web3 provider

useEffect(() => {
    window.ethereum.on("accountsChanged", accounts => {
      if (accounts.length > 0) setAccount(accounts[0]);
      else setAccount("");
    });
}, []);
Posted by: Guest on June-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language