0

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();

and

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

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

2 Answers 2

1
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();
0

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

if(window.ethereum){
    ethereum.enable().then(function(acc){
        App.account = acc[0];
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.