truffle-box / react-box

Truffle, Webpack and React boilerplate.
https://truffle-box.github.io/
MIT License
736 stars 251 forks source link

Can't find injected web3 using ./utils/getWeb3.js #5

Closed andytudhope closed 7 years ago

andytudhope commented 7 years ago

The latest commit that changes how the web3 object is handled seems to break things for me. It does not see the injected web3 object and defaults to the local one every time, no matter which network I connect MetaMask to.

OS: Mac 10.12.5 Browser: Chrome

I'm a newb to React, so forgive me, but my sense was that there was something amiss with the lifecycle hooks and waiting for the load event. I tried changing the code in app.js to make a button that would only call getWeb3 when clicked, but that failed even more, so the issue is definitely with the getWeb3.js file. I'm just not sure how to edit it to get it to pick up the injected web3 at the right time...

screen shot 2017-06-27 at 10 42 55 am
andytudhope commented 7 years ago

fixed by adding let web3 = window.web3 in getWeb3.js

scorpion9979 commented 5 years ago

window.web3 does not always provide a consistent API. I've had several issues with this on mobile dApp browsers, since it was returning an older version of web3 with different API. The solution is to use new Web3(Web3.currentProvider) instead, where Web3 is the one imported from the dependencies, not the one in the window.

scorpion9979 commented 5 years ago

99