I'm trying to use Web3 to access the current account I have selected on Metamask by doing web3.eth.accounts[0] in order to display it on my UI (in VueJS). However web3.eth.accounts[0] always returns the same account, the first one of the 10 given to me by Ganache TestRPC.
Even if I switch to the 8th account (screenshot below) and refresh the app, console.log(web3.eth.accounts[0])
still outputs the first account in the array.
Here's my code (in Vuejs, contract has already been created):
var ethereumUri = 'http://127.0.0.1:7545';
let web3 = new Web3(new Web3.providers.HttpProvider(ethereumUri));
if (!web3.isConnected()) {
return 'Unable to connect to ethereum node at ' + ethereumUri
}else{
var escrowContract = web3.eth.contract(abi); //abi initalized at start
var instance = escrowContract.at(this.contractAddress); //contractAddress is initialized at the start
console.log(web3.eth.accounts);
console.log(web3.eth.accounts[0]);
}
How would I make web3 output the current selected account address in Metamask?
Thanks!