Search code examples
blockchainethereumweb3jsmetamaskdecentralized-applications

Metamask stopping to inject web3.js


As we know, metamask will no longer inject web3.js starting Jan 13, 2020. What are the approaches we should take to stop the dependency on web3?

Also how can we test it out with the existing Metamask that is injecting web3.js as of now.


Solution

  • window.ethereum will still contain Web3 Provider. You can use it setup your web3 convenience library of choice such as web3.js or ethers.js. For example:

    const Web3 = require('web3');
    // web3 lib instance
    const web3 = new Web3(window.ethereum);
    // get all accounts
    const accounts = await web3.eth.getAccounts();