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).
In provider options, you have not specified the provider for coinbase. You can use WalletLink for connection using Coinbase wallet.
You will have to add a custom provider in the we3bmodal provider Options, like this
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: INFURA_ID
}
},
'custom-coinbase': {
display: {
logo: 'images/coinbase.svg',
name: 'Coinbase',
description: 'Scan with WalletLink to connect',
},
options: {
appName: 'app', // Your app name
networkUrl: `https://mainnet.infura.io/v3/${INFURA_ID}`,
chainId: CHAIN_ID,
},
package: WalletLink,
connector: async (_, options) => {
const { appName, networkUrl, chainId } = options
const walletLink = new WalletLink({
appName
});
const provider = walletLink.makeWeb3Provider(networkUrl, chainId);
await provider.enable();
return provider;
},
}
};
const web3Modal = new Web3Modal({
network: 'ropsten',
cacheProvider: true,
providerOptions: providerOptions
});
I got the reference from this Git issue
Best Answer
Coinbase Wallet does its own WalletLink protocol that is not supported by other wallets.
See also: Connecting the wallet of to your dApp and different Ethereum wallet types