I am facing some problem with metamask.
I ve copied the code below from the metamask documentation to load the web3 but i get always web3.eth.accounts[0] returns undefined when i try to get the account's address even if metamask is connected to ropsten. The same code works with Mist perfectly.
window.addEventListener('load', function() {
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
console.log("Metamask used");
} else {
console.log('No web3? You should consider trying MetaMask!')
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/token"));
}
console.log('test1'+web3.eth.accounts[0]);
});
console.log('test'+web3.eth.accounts[0]);
i get the output of the first log.