Is there a way to automatically open metamask unlock prompt ?

Since I am able to detect metamask is available, instead of redirecting user to unlock.html I would prefer to try automatically prompt user to unlock it. If user cancels or ignores the unlock request automatic redirect would take place.

window.addEventListener('load', function(){
        if (typeof web3 !== 'undefined') {
         // Use Mist/MetaMask's provider
         console.log('Web3 exist!')
         // If the browser has injected Web3.js
           console.log("Injected web3 ");
           window.web3old = window.web3;
           console.log("Moved window.web3 to window.web3old");
           window.web3 = new Web3(window.web3.currentProvider);
           console.log("Replaced old window.web3 with web3 1.0.0 36");

           if (window.web3.eth.accounts.length){
             const account = window.web3.eth.accounts[0];


           } else {
             console.log('Metamask is locked');
             // try to prompt for Unlock
             window.location.href = '/unlock.html';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.