I'm using react and javascript. For whatever reason, I've tried a few methods and it doesn't seem to be opening metamask.

await window.ethereum.enable();


window.web3 = new Web3(web3.currentProvider);

But in the second instance it has no clue what web3 is.

import Web3 from 'web3';

At the top of the file and then during a componentwillmount or whatnot, these lines...

window.web3 = new Web3(window.ethereum);
await window.ethereum.enable();

Metamask extension loads the ethereum provider on window. The following code will throw a MetaMask prompt to enable connection:

        App.account = acc[0];

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.