Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:26
Show Gist options
  • Save percybolmer/222e4dd1b8410f11bc873badae79a7ac to your computer and use it in GitHub Desktop.
Save percybolmer/222e4dd1b8410f11bc873badae79a7ac to your computer and use it in GitHub Desktop.
// connectMetaMask is used to connect to MetaMask and ask permission to grab account information
function connectMetaMask() {
// We need to make the connection to MetaMask work.
// Send Request for accounts and to connect to metamask.
window.web3.requestAccounts()
.then((result) => {
// Whenever the user accepts this will trigger
setAccounts(result);
})
.catch((error) => {
// Handle errors, such as when a user does not accept
throw new Error(error);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment