So I have this default metamask event listener that checks is a user is connected. I have added an extra function(line 4) that will display the wallet address in a container. However, if I try to append the container with a different message when metamask is not detected, I get a empty container. What am I missing?
window.addEventListener('load', function() {
if (typeof web3 !== 'undefined') {
web3js = new Web3(web3.currentProvider);
$('#eth-address').append(web3.eth.accounts[0]) // display address
} else {
console.log('No web3? You should consider trying MetaMask!')
web3js = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
$('#eth-address').append('please connect using metamask')}
startApp() })
Is this a case where metamask is installed; so there is a provider but the account is locked?
web3 is defined, but then the accounts objects is empty, maybe do a console.log to check what is happening.
If the account is locked then one thing you can do a set an interval to keep checking for the accounts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With