2

From 2nd November MetaMask will not expose user accounts by default anymore and we must do it. I'm confused about how we are supposed to integrate that in our dapps.

For example, I have a standard web3.js file with the following code:

import Web3 from 'web3';



let web3;
if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
  // metamask is running
  web3 = new Web3(window.web3.currentProvider);
} else {
  //user is not running metamask
  // create provider through infura
  const provider = new Web3.providers.HttpProvider(
    // pass url of remote node
    'https://rinkeby.infura.io/v3/censored'
  );
  web3 = new Web3(provider);

}
export default web3;

Should changes be in the web3.js file? Or, should I create a button on the website which must be clicked by the user to give me access to his MetaMask account?

0

Found the solution! You most likely have a web3.js file that you export to your default app. The solution is simple:

import Web3 from 'web3';



let web3;
if (window.ethereum) {
  // metamask is available
  window.ethereum.enable();    
  web3 = new Web3(window.web3.currentProvider);
} else {
  //user is not running metamask
  // create provider through infura
  const provider = new Web3.providers.HttpProvider(
    // pass url of remote node
    'https://rinkeby.infura.io/v3/censored'
  );
  web3 = new Web3(provider);

}
export default web3;

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.