Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:26
Show Gist options
  • Save percybolmer/e51eb32e14dbaf7a4e0174d8bb98a567 to your computer and use it in GitHub Desktop.
Save percybolmer/e51eb32e14dbaf7a4e0174d8bb98a567 to your computer and use it in GitHub Desktop.
// this will trigger whenever the App function is called, which index.js runs at startup
useEffect(() => {
// Here we check if there is web3 support
if (typeof web3 !== 'undefined') {
window.web3 = new Web3(window.web3.currentProvider)
// Check if its MetaMask that is installed
if (window.web3.currentProvider.isMetaMask === true) {
connectMetaMask();
connectToSelectedNetwork();
} else {
// Another web3 provider, add support if you want
}
}else {
// The browser has no web3
// Suggest the user to install a web3 compatible browser plugin
throw new Error("No web3 support, redirect user to a download page or something :) ");
}
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment