dappuniversity / election

A Decentralized Ethereum Voting Application Tutorial
566 stars 507 forks source link

eth.web3.accounts #17

Open jamsubzero opened 5 years ago

jamsubzero commented 5 years ago

web3.eth.accounts is not working in the console and even in the js test. after long googling, I realize that I can now use eth.web3.getAccounts().. But the problem since this is a method, I can't pass index to getAccounts to get the first account(account 0).

So basically my problem is how can I get a single account from getAccounts function.. anyone have an idea?

aemxn commented 5 years ago

I'm encountering the same issue, but I skipped that part and only test my contract using the test framework.

You can however achieve what you're looking for by using promises in js to return a single account. Not sure how to do it in truffle, I think it's important to know this in order for us to easily debug our contract.

Hope someone can point this out clearly.

EDIT: Check this out. Excerpt from the answer in the link:

async function getAccount(id) {
    let accounts = await web3.eth.getAccounts();
    return accounts[id];
}

You'll need to execute await getAccount(0) from an async function of course (or use a Promise).

kamskanagi commented 5 years ago

I get that same issue. Also when i do "npm run dev" it will show the picture below. Even when i connect with the metamask.

Screen Shot 2019-04-09 at 11 50 44 AM

In the beginning i though it was my code, but i clone your repository and run it. its still the same issue.

TheNewMrRobot commented 5 years ago

I get that same issue. Also when i do "npm run dev" it will show the picture below. Even when i connect with the metamask.

Screen Shot 2019-04-09 at 11 50 44 AM

In the beginning i though it was my code, but i clone your repository and run it. its still the same issue.

for me also

theMoe commented 5 years ago

I have the same issue. How can we fix this?

suraj1611 commented 5 years ago

can somebody help I have the same issue..the contract is not loading. I have also used ethereum.enable() as suggested by some users.

dyttokaa commented 5 years ago

can somebody help I have the same issue..the contract is not loading. I have also used ethereum.enable() as suggested by some users.

hey @suraj1611, @theMoe and @vignesh1010! i have the same issue, did anybody manage ti fix it?

incredible5 commented 4 years ago

I get that same issue. Also when i do "npm run dev" it will show the picture below. Even when i connect with the metamask.

Screen Shot 2019-04-09 at 11 50 44 AM

In the beginning i though it was my code, but i clone your repository and run it. its still the same issue.

Same issue bro

crashandlearn commented 4 years ago

This problem has been solved in another thread

ujjwaljain08 commented 3 years ago

can somebody help I have the same issue..the contract is not loading. I have also used ethereum.enable() as suggested by some users.

hey @suraj1611, @theMoe and @Vignesh1010! i have the same issue, did anybody manage ti fix it?

do u get any solution ??

SreemanthG commented 3 years ago

You can try using this instead web3.eth.getAccounts().then(function(e){return e[0]}) Here it returns address of 0 index.

If you want to use it with the vote function you can try this

web3.eth.getAccounts().then(function(e){accountid1= e[0]}) 
app.vote(1, { from: accountid1})