I'm working on a simple project. Part of that requires retrieving accounts from the web3 provider asynchronously (so that they can be used as variables in the code of my frontend). My initial investigation suggested this should be simple enough - web3.eth.getAccounts() returns a promise, so you should simply be able to await it, and I in fact found examples of people doing just that online. However, when I tried that, it didn't work. I initially used a simple structure:
var currentAccount = await web3.eth.getAccounts()
I then tried putting it inside an async method:
async function getCurrentAccount(){
currentAccount = await web3.eth.getAccounts();
console.log("getCurrentAccount has resolved, returning a value of " + currentAccount);
return currentAccount;
}
But running this with currentAccount = getCurrentAccount() simply produced the following error:
inpage.js:1 Uncaught TypeError: e is not a function
at inpage.js:1
at inpage.js:1
at inpage.js:1
at inpage.js:1
at i (inpage.js:1)
at inpage.js:1
at inpage.js:1
at u (inpage.js:1)
at s (inpage.js:1)
at inpage.js:1
I'm not sure what's causing this. Anyone got any advice?
Thanks
currentAccount = await getCurrentAccount()
because the function isasync
? In any case, I don't think this has anything to do with Ethereum... your issue is most likely about JavaScript andasync
/await
.