Created
May 31, 2022 07:58
-
-
Save shishircse06/9b6f6698e85a31e3b4c529dce9577e80 to your computer and use it in GitHub Desktop.
metamask connected status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkConnection = () => { | |
// Check if browser is running Metamask | |
if (window.ethereum) { | |
web3 = new Web3(window.ethereum); | |
} else if (window.web3) { | |
web3 = new Web3(window.web3.currentProvider); | |
}; | |
// Check if User is already connected by retrieving the accounts | |
web3.eth.getAccounts().then(e => | |
{ | |
let firstAcc=e[0]; | |
console.log(firstAcc); | |
} | |
); | |
}; | |
checkConnection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment