Skip to content

Instantly share code, notes, and snippets.

@ylv-io
Last active January 14, 2019 12:09
Show Gist options
  • Save ylv-io/56bddbf64058d29ec85aee306e4b0664 to your computer and use it in GitHub Desktop.
Save ylv-io/56bddbf64058d29ec85aee306e4b0664 to your computer and use it in GitHub Desktop.
window.addEventListener('load', () => {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
web3js = new Web3(web3.currentProvider);
} else {
console.log('No web3? You should consider trying MetaMask!');
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
web3js = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
}
// Now you can start your app & access web3 freely:
startApp();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment