Skip to content

Instantly share code, notes, and snippets.

@shishircse06
Created May 31, 2022 07:58
Show Gist options
  • Save shishircse06/9b6f6698e85a31e3b4c529dce9577e80 to your computer and use it in GitHub Desktop.
Save shishircse06/9b6f6698e85a31e3b4c529dce9577e80 to your computer and use it in GitHub Desktop.
metamask connected status
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