5

Since metamask communicated that they will no longer inject web3 by default (https://medium.com/metamask/https-medium-com-metamask-breaking-change-injecting-web3-7722797916a8) I tried to use their new suggested method to access accounts.

Here is the code:

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!');
    }
});

This works and I get access to the account, however, there is no request the user has to accept in metamask. Why is that? And how can I simulate the request to prepare my UI for this?

moritzfelipe
  • 155
  • 5

2 Answers2

1

Just spotted this link - as I am running into a similar issue - Privacy Mode is still not enabled in metamask - they are indicating it will be in v4.18...

https://github.com/MetaMask/metamask-extension/issues/5676

dubirl
  • 58
  • 6
  • Just to add to this - in the last day or few hours MetaMask has now updated to v.5.0 and the private option is showing – dubirl Nov 07 '18 at 00:16
  • Thank you just download 5.0 and tested it with privacy mode, this works as expected. – moritzfelipe Nov 07 '18 at 15:05
  • Hi, I have tested this again and it now working with V 5.0 of Metamask - the app.js file needs to be updated again - the code and instructions have been updated I have tested from end to end and it now worked as expected https://www.truffleframework.com/tutorials/pet-shop – dubirl Nov 11 '18 at 16:19
0

Did you enable Privacy mode? Privacy mode is disabled by default until the new release comes out.

You have to download Metamask v4.16 as far as I know because I couldn't find the option to enable privacy mode on v4.17. You can download it here:

https://github.com/MetaMask/metamask-extension/pull/4703#issuecomment-434615101

Then install it manually

Dar K
  • 35
  • 4