3

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,

1 Answer 1

5

Mist inserts a mist object you can check in the browser.

if (typeof(mist) !== "undefined") {
 // browser is running in mist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.