Whenever I want to use web3
, I initialize it as follows:
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
The provider works whether I'm in Mist or another browser (while geth
is running locally). How can I distinguish between the two cases? Either in browser or server (maybe in req
object of Node?), is there any way I can see if the user is using the Mist browser or not?
Thanks,