【问题标题】:blockchain tutorial Error: The send transactions "from" field must be defined区块链教程错误:必须定义发送交易“来自”字段
【发布时间】:2021-04-26 21:01:33
【问题描述】:

我正在学习 dappuniversity 的区块链教程。

当我在行中创建任务时

await App.todoList.createTask(content)

从行 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)

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

【问题讨论】:

  • 您使用什么样的提供商? MetaMask(如 cmets 和错误消息定义所暗示的)或其他(如 Infura)?如果是 MetaMask,您是否已导入任何帐户并且您是否允许该应用使用这些帐户中的至少一个?
  • 是的,我正在使用 Metamask,我已经允许了。我正在将 Ganache 用于本地以太坊区块链。
  • 我猜您的web3 没有设置默认帐户,但我无法验证。尝试将此行附加到loadAccount 函数(在App.account = ... 之后):web3.eth.defaultAccount = web3.eth.accounts[0];
  • 我也添加了,但它是一样的。我更新了 trufflecontract 版本,但没有运气。

标签: ethereum truffle


【解决方案1】:

由于最近的 Metamask 更新以及从 web3.currentProviderwindow.ethereum 的移动,我遇到了上述答案的问题

我能够使用 await App.todoList.createTask(content, {from: App.account})

【讨论】:

    【解决方案2】:

    我正在使用最新的松露/合同。我需要在我的 createTask 方法中指定 from 帐户,如下所示:

    await App.todoList.createTask(content,  { from:  web3.eth.defaultAccount})        
    

    这行得通。

    【讨论】:

      【解决方案3】:

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

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

      然后将App的账号传递给createTask方法:await App.todoList.createTask(content, { from: App.account })

      【讨论】:

        【解决方案4】:

        我在 Remix 上与部署在 Rinkeby 上的合约交互时也发生了同样的事情。我为环境选择了injected web3,但account字段为空。

        它发生是因为我先拒绝了与 metamask 的连接,然后没有收到任何其他与 metamask 连接的请求。所以我刷新了混音,锁定和解锁的元掩码。它发送连接到元掩码的请求

        【讨论】:

          猜你喜欢
          • 2022-12-15
          • 1970-01-01
          • 2018-11-04
          • 2017-12-08
          • 1970-01-01
          • 2020-09-08
          • 2020-03-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多