Last active
May 28, 2022 05:19
-
-
Save duartefdias/b05c8f4882b08b5764e619a6ecdef120 to your computer and use it in GitHub Desktop.
This file contains 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
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