Skip to content

Instantly share code, notes, and snippets.

@Sowmayjain
Created March 9, 2019 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sowmayjain/adb69fa092e5c5f9e3a6914ac433163c to your computer and use it in GitHub Desktop.
Save Sowmayjain/adb69fa092e5c5f9e3a6914ac433163c to your computer and use it in GitHub Desktop.
// 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