0

I am following a tutorial from Dapp University about building Election Smart Contract. When I run this command in the console:

app.vote(1, {from: web3.eth.accounts[0] })

I get the following error:

Thrown: <Error: The send transaction "from" field must be defined!

I know that "web3.eth.accounts" has been depreciated and I have tried a few ways to solve it but so far no luck.

2
  • What version of web3.js are you using? Oct 6, 2019 at 2:49
  • @goodvibration version 1.0.0
    – Klaudia
    Oct 6, 2019 at 8:41

2 Answers 2

0

How many arguments does the vote method take? In web3.js the smart contract method's arguments are interpreted first, and the last argument is expected to be transaction options such as: { from, gas, gasPrice }

If you are supplying a different number of arguments than is expected, web3.js will try to find the from field from an argument where it's not present.

Also, you can try adding this line to your code, to make sure it still works and has not been removed yet. console.log('Account 0', web3.eth.accounts[0])

0

that error is because you pass account= '' .(in the from:) i think is your web3 version(can you check the version in console with "web3.version") and with web3 1.x.x can you try : web3.currentProvider.selectedAddress to get the address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.