let accounts = web3.eth.getAccounts() 显示未定义,app.vote(1,{ fro



我是solidity的新手,正在通过一个简单的网络应用程序进行探索。我正在尝试制作一个接受来自不同帐户的投票的候选人投票网络应用程序。所以我尝试了以下一些步骤

truffle(development) > let app = await Election.deployed() 
truffle(development) > app
truffle(development) > let accounts = web3.eth.getAccounts()
truffle(development) > app.vote(1,{ from: accounts[1] })

在最后一行中,它显示错误:

Thrown:
Error: The send transactions "from" field must be defined!
at evalmachine.<anonymous>:0:5
at sigintHandlersWrap (vm.js:269:15)
at Script.runInContext (vm.js:124:14)
at runScript (C:UsersKrishna Veer SinghAppDataRoamingnpmnode_modulestrufflebuildwebpack:packagescorelibconsole.js:222:1)
at Console.interpret (C:UsersKrishna Veer SinghAppDataRoamingnpmnode_modulestrufflebuildwebpack:packagescorelibconsole.js:237:1)
at ReplManager.interpret (C:UsersKrishna Veer SinghAppDataRoamingnpmnode_modulestrufflebuildwebpack:packagescorelibrepl.js:129:1)
at bound (domain.js:420:14)
at REPLServer.runBound [as eval] (domain.js:433:12)
at REPLServer.onLine (repl.js:715:10)
at REPLServer.emit (events.js:210:5)
at REPLServer.EventEmitter.emit (domain.js:476:20)
at REPLServer.Interface._onLine (readline.js:316:10)
at REPLServer.Interface._line (readline.js:693:8)
at REPLServer.Interface._ttyWrite (readline.js:1019:14)
at REPLServer.self._ttyWrite (repl.js:792:7)
at ReadStream.onkeypress (readline.js:191:10)
at ReadStream.emit (events.js:210:5)
at ReadStream.EventEmitter.emit (domain.js:476:20)
at emitKeys (internal/readline/utils.js:433:14)
at emitKeys.next (<anonymous>)

当我第一次尝试相同的代码时,它工作正常,但现在它不起作用。 请帮助我摆脱困境。

似乎无法识别发起的帐户价值,请尝试使用

let accounts = await web3.eth.getAccounts();

您可以通过以下方式将默认帐户设置为帐户[1]

web3.eth.defaultAccount = accounts[1]

最新更新