ethavatar icon indicating copy to clipboard operation
ethavatar copied to clipboard

No Accounts Exposed by Default

Open filips123 opened this issue 5 years ago • 1 comments

MetaMask and other dapp browsers will soon have different way to access provider. You would need to update Web3 provider to window.ethereum and call ethereum.enable to enable it.

I can fix this, but I will wait to be #12 merged.


On November 2nd, MetaMask and other dapp browsers will stop exposing user accounts by default. Instead, dapps must request access using a new provider method: provider.enable(). The privacy-preserving strategy is outlined below.

See https://medium.com/metamask/https-medium-com-metamask-breaking-change-injecting-web3-7722797916a8 for details.

window.addEventListener('load', async () => {
    // Modern dapp browsers...
    if (window.ethereum) {
        window.web3 = new Web3(ethereum);
        try {
            // Request account access if needed
            await ethereum.enable();
            // Acccounts now exposed
            web3.eth.sendTransaction({/* ... */});
        } catch (error) {
            // User denied account access...
        }
    }
    // Legacy dapp browsers...
    else if (window.web3) {
        window.web3 = new Web3(web3.currentProvider);
        // Acccounts always exposed
        web3.eth.sendTransaction({/* ... */});
    }
    // Non-dapp browsers...
    else {
        console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
    }
});

filips123 avatar Oct 25 '18 19:10 filips123

I've fixed this in cryptoquick/ethavatar#1, so it should be merged into gitcoinco/ethavatar#12 and then in this repository.

filips123 avatar Nov 22 '18 14:11 filips123