Created
December 27, 2020 19:19
-
-
Save wissalHaji/865d6b586d40651cc5ad54981d66b7f2 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
const getWeb3 = () => { | |
return new Promise((resolve, reject) => { | |
window.addEventListener("load", async () => { | |
if (window.ethereum) { | |
const web3 = new Web3(window.ethereum); | |
try { | |
// ask user permission to access his accounts | |
await window.ethereum.request({ method: "eth_requestAccounts" }); | |
resolve(web3); | |
} catch (error) { | |
reject(error); | |
} | |
} else { | |
reject("Must install MetaMask"); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment