1

I am building a very simple dapp. At first I want to initiate web3 on the webpage and then enable it so that I can access web3.eth.getAccounts().

MetaMask, and Opera Mobile both have a window.ethereum.enable() function which will prompt the user to allow the webpage to access the wallet. Once they do that, I can call web3.eth.getAccounts, like this:

    ethereum.enable().then(() => {
        web3.eth.getAccounts((error, accounts) => {
          console.log(accounts)
        })
      })
    }

Coinbase Wallet (aka Toshi) doesn't have window.ethereum.enable, (or equivalent) so I can't access getAccounts()

Anyone know how to get it to work?

  • I'd suggest to try some of the workarounds from the old MetaMask documentation github.com/MetaMask/faq/blob/master/detecting_metamask.md, ie for example web3.currentProvider. – Ismael Apr 25 '19 at 22:11
  • That still doesn't shed any light on how to enable / unlock the user's wallet in order to make transactions – simbro Apr 26 '19 at 10:05
2

It turns out that in Coinbase Wallet, web3 is enabled by default, so you just have to do:

    web3.eth.getAccounts((error, accounts) => {
      console.log(accounts)
    })

...and you don't need to call ethereum.enable first. I'm they will probably change this though, as it's a security concern (all sites visited using that browser will be able to see your address).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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