4

I am following a blockchain tutorial from dappuniversity.

When I create the task in the line

await App.todoList.createTask(content)

from line https://github.com/dappuniversity/eth-todo-list/blob/e3ed9a2cefb581c09730250c56c9d30a19cc63c8/src/app.js#L115

I get the following error :

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)

Do I need to define a 'from' field somewhere?

Katlock
  • 1,200
  • 1
  • 17
  • 41
  • What kind of provider are you using? MetaMask (as the comments and error message definitions sugest) or other (such as Infura)? If MetaMask, do you have any accounts imported and did you allow the app to use at least one of these accounts? – Petr Hejda Apr 26 '21 at 21:11
  • Yes, I am using Metamask and I have allowed it. I am using Ganache for a local Ethereum blockchain. – Katlock Apr 26 '21 at 21:13
  • I'm guessing that your `web3` doesn't have a default account set, but I have no way to verify it. Try appending this line to the `loadAccount` function (after the `App.account = ...`): `web3.eth.defaultAccount = web3.eth.accounts[0]`; – Petr Hejda Apr 26 '21 at 21:30
  • I added that too but it's the same. I updated the trufflecontract version and no luck. – Katlock Apr 27 '21 at 17:59

4 Answers4

5

With the latest dependencies, none of the above answers were working for me. I had to edit the loadAccount method:

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

then pass the App's account to the createTask method: await App.todoList.createTask(content, { from: App.account })

3

I was running into issues with the above answer which appears due to recent Metamask updates and that moving from web3.currentProvider to window.ethereum

I was able to make this work using await App.todoList.createTask(content, {from: App.account})

travelerrrrrrr
  • 193
  • 3
  • 14
2

I am using the latest truffle/contract. I needed to specify the from account in my createTask method like the following:

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

This worked.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Katlock
  • 1,200
  • 1
  • 17
  • 41
0

Same happened to me on Remix while interacting with the contract deployed on Rinkeby. I chose injected web3 for the environment, But account field was empty.

enter image description here

It happended because I rejected the connection to metamask first and then did not get any other request to connect with metamask. So I refreshed remix, locked and unlocked metamask. It sent request to connect to metamask

Yilmaz
  • 35,338
  • 10
  • 157
  • 202