Skip to content

Instantly share code, notes, and snippets.

@duartefdias
Last active May 28, 2022 05:19
Show Gist options
  • Save duartefdias/b05c8f4882b08b5764e619a6ecdef120 to your computer and use it in GitHub Desktop.
Save duartefdias/b05c8f4882b08b5764e619a6ecdef120 to your computer and use it in GitHub Desktop.
function connectWallet() {
if (window.ethereum) {
console.log('MetaMask is installed');
window.web3 = new Web3(window.ethereum);
window.ethereum.send('eth_requestAccounts').then(function() {
// Get account address
window.ethereum.request({ method: 'eth_accounts' })
.then(function(accounts) {
if (accounts.length > 0) {
buyerAddress = accounts[0];
} else {
connected = false;
}
});
});
} else if (window.web3) {
window.web3 = new Web3(window.web3.currentProvider);
connected = true;
} else {
connected = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment