Im new to web3 and Im using following code to connect my UI to web3.

// Modern dapp browsers...
    if (window.ethereum) {
        window.web3 = new Web3(ethereum);
        try {
            // Request account access if needed
        } catch (error) {
            // User denied account access...
    // Legacy dapp browsers...
    else if (window.web3) {
        window.web3 = new Web3(web3.currentProvider);
        // Acccounts always exposed

    // Non-dapp browsers...
    else {
        console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');

    var version = web3.version;

The output of console is this, which means it is using 0.20.3 version of web3. enter image description here

who is actually injecting this version? If metamask is injecting then why it is not injecting the latest version which is 1.0.0-beta.

P.S: metamask version is 6.0.1

1 Answer 1


You can 'override' the version injected by Metamask, so that you get more cross-browser/cross-wallet compatibility.

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js"></script>
    const web3 = new Web3(window.web3.currentProvider);

See for example the bounty given by Opera

  • Yes, worked for me. Using Metamask 7.2.2. Commented Oct 11, 2019 at 13:11

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.