I am writing DApp in react, and basically I want to initialize web3, unlock account, and display it. Having
web3 in my
package.json In the
onload I've tried to go following:
let Web3 = require('web3'); let instance = new Web3(window.web3.currentProvider);
First of all, I am completely missing the point of such a step. What do we do here? What is the difference between
Second, what line should I use and why?
console.log(window.web3.eth.accounts); // this? console.log(instance.eth.accounts); // or that?
I want to figure out browser-agnostic scheme, that would work on Metamask, Opera, and on mobile browsers like Cipher.
I've tried a bunch of schemes, on some platforms I'm missing
web3.eth.accounts, but accounts can be availble via
I've looked at following, but still can't generalize:
- Better pattern to detect web3 default account when using metamask
- New web3 method to request account access from dapp browser, no request
I run into a problem that it's neither straightforward, nor documented process. To face such a problem, lets create a place with answer, detailing basics of init and unlock procedure, that should work in any browser, for any web3.