Web3 – How to Enable Web3 in Coinbase Wallet?

dapp-developmentweb3js

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?

Best Answer

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).