I have searched severally on how to use web3 with metamask without nodejs without any success. I want to be able to get an instance of a user's metamask account through web3 and vanilla javascript without having to go through nodejs and all it's dependencies. I have included web3.mim.js on the head tag and have this code running fine.
window.addEventListener('load', function () {
if (typeof web3 !== 'undefined') {
console.log('Web3 Detected! ' + web3.currentProvider.constructor.name);
window.web3 = new Web3(web3.currentProvider);
} else {
console.log('No Web3 Detected... using HTTP Provider')
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
})
The issue however is that when i try to get default account using web3.eth.defaultAccount
i get a null value returned to me.
How can i get access to the current account on metamask?
I am running the script in an apache server.