Skip to content

Instantly share code, notes, and snippets.

@nunofernandes-plight
Forked from frozeman/mistweb3.js
Created April 2, 2016 15:32
Show Gist options
  • Save nunofernandes-plight/22f63d265fe5589aff13ff099ef3aced to your computer and use it in GitHub Desktop.
Save nunofernandes-plight/22f63d265fe5589aff13ff099ef3aced to your computer and use it in GitHub Desktop.
Mist web3 loading proposal
/*
Basically "web3" comes from Mist,
but "Web3" CAN come from the dapp.
A Dapp has 3 ways to use web3.
2. and 3. would work when in Mist and outside.
*/
// 1. simply use, web3 comes already defined
web3
// 2. optional use web3 from mist, OR load if outside of mist
if(typeof web3 === 'undefined')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
// 3. always use web3 provided by the dapp ("Web3" won't be supplied by Mist), but the provider from mist
if(typeof web3 !== 'undefined')
web3 = new Web3(web3.currentProvider);
else
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
// Add RPC version?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment