区块链教程错误:必须定义发送交易“来自”字段

Son*_*nam 4 ethereum truffle

我正在关注 dappuniversity 的区块链教程。

当我在行中创建任务时

await App.todoList.createTask(content)
Run Code Online (Sandbox Code Playgroud)

来自行 https://github.com/dappuniversity/eth-todo-list/blob/e3ed9a2cefb581c09730250c56c9d30a19cc63c8/src/app.js#L115

我收到以下错误:

Uncaught (in promise) Error: The send transactions "from" field must be defined!
    at Method.inputTransactionFormatter (truffle-contract.js:50747)
    at truffle-contract.js:51228
    at Array.map (<anonymous>)
    at Method.formatInput (truffle-contract.js:51226)
    at Method.toPayload (truffle-contract.js:51261)
    at Eth.send [as sendTransaction] (truffle-contract.js:51551)
Run Code Online (Sandbox Code Playgroud)

我需要在某处定义“来自”字段吗?

Que*_*urs 5

使用最新的依赖项,上述答案都不适合我。我必须编辑 loadAccount 方法:

loadAccount: async () => {
    // Set the current blockchain account
    const accounts = await web3.eth.getAccounts();
    App.account = accounts[0];
},
Run Code Online (Sandbox Code Playgroud)

然后将应用程序的帐户传递给 createTask 方法:await App.todoList.createTask(content, { from: App.account })