让 accounts = web3.eth.getAccounts() 显示未定义和 app.vote(1, from: accounts[1] ) 显示错误
Posted
技术标签:
【中文标题】让 accounts = web3.eth.getAccounts() 显示未定义和 app.vote(1, from: accounts[1] ) 显示错误【英文标题】:let accounts = web3.eth.getAccounts() shows undefined and app.vote(1, from: accounts[1] ) showing error让 accounts = web3.eth.getAccounts() 显示未定义和 app.vote(1, from: accounts[1] ) 显示错误 【发布时间】:2020-09-08 08:59:58 【问题描述】:我是 Solidity 的新手,我正在通过一个简单的 web 应用程序来探索它。我正在尝试制作一个接受来自不同帐户的投票的候选人投票网络应用程序。所以我尝试了以下一些步骤
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:\Users\Krishna Veer Singh\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:222:1)
at Console.interpret (C:\Users\Krishna Veer Singh\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:237:1)
at ReplManager.interpret (C:\Users\Krishna Veer Singh\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\repl.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>)
当我第一次尝试相同的代码时,它运行良好,但现在无法运行。 请帮助我摆脱困境。
【问题讨论】:
【参考方案1】:好像不识别初始账户值,试试用
let accounts = await web3.eth.getAccounts();
您可以通过
将默认帐户设置为帐户[1]web3.eth.defaultAccount = accounts[1]
【讨论】:
以上是关于让 accounts = web3.eth.getAccounts() 显示未定义和 app.vote(1, from: accounts[1] ) 显示错误的主要内容,如果未能解决你的问题,请参考以下文章
让 accounts = web3.eth.getAccounts() 显示未定义和 app.vote(1, from: accounts[1] ) 显示错误
ORA-28000: the account is locked-的解决办法
How to let your website login with domain account when using IIS to deploy it?
如何在Python中创建一个递归函数来创建一个映射Odoo 8关系字段记录的字典?
path('accounts/', include(accounts.urls)), NameError: name 'accounts' 没有定义