blockchain tutorial Error: The send transactions "from" field must be defined

Viewed 2463

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?

4 Answers

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})

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.

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 })

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

Related