Created
March 9, 2019 08:19
-
-
Save Sowmayjain/adb69fa092e5c5f9e3a6914ac433163c 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
// starting up a dapp | |
window.addEventListener('load', async () => { | |
if (window.ethereum) { // Modern dapp browsers... | |
window.web3 = new Web3(ethereum); | |
try { | |
await ethereum.enable(); // Request account access if needed | |
} catch (error) { | |
console.log('User denied permission to use their Ethereum account.'); | |
} | |
} else if (window.web3) { // Legacy dapp browsers... | |
window.web3 = new Web3(web3.currentProvider); | |
} else { // Non-dapp browsers... | |
console.log('Non-Ethereum browser detected. You should consider trying MetaMask!'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment