[Ethereum] What does MetaMask mean by stop injecting web3.js

browserschain-reorganizationdappsmetamaskweb3js

MetaMask announced that they will stop injecting web3.js here. I know previously MetaMask will add a global variable in browser window.web3 and this global lowercase web3 variable will be deprecated soon. But in my DApp, I use MetaMask as a provider to the original Web3.js library (i.e. captical Web3). Will my usage be affected by MetaMask stopping injecting web3.js?

I also posted another question here, where I find web3.js cannot listen to on("changed") events in smart contract using MetaMask offered provider ethereum. If I still want to use MetaMask and Web3.js in my DApp, how can I get notified when events emitted in smart contracts are removed due to chain reorganization?

Thanks in advance.

Best Answer

If MetaMask will stop injecting web3 this means web3.currentProvider is not gonna work anymore properly. My advice is to handle the change and not getting your app crashed by downloading your own web3 library and using ethereum provider. This variable was introduced in the latest versions. Example:

const Web3 = require('web3'); // import web3 v1.0 constructor from node_modules
if(window.ethereum) {
    const web3Instance = new Web3(window['ethereum']);

    var methods = {
        getAddressETHBalance: function(address)    {
            return new Promise(function(resolve, reject) {
                resolve(web3Instance.eth.getBalance(address));
            });
        }
    };

    methods.getAddressETHBalance(<ADDRESS>);
} else {
    alert('Missing MetaMask extention.');
}