Error: Sender account not recognized sending from ganache account[0] to MetaMask

Trying to send test ether from my Ganache account[0] to metamask account but getting this error

truffle(develop)> web3.eth.sendTransaction({to: "0x8C9ad9Ff0655Db057317FDd37B4aabcC5411E87D", from:accounts[0], value: web3.utils.toWei("2", "ether")});11E87D", from:accounts[0], value: web3.utils.toWei("2", "ether")});
Uncaught Error: Returned error: sender account not recognized     

:computer: Environment
Truffle v5.1.56 (core: 5.1.56)
Solidity v0.5.16 (solc-js)
Node v12.19.0
Web3.js v1.2.9

:memo:Details

:1234: Code to reproduce

1 Like

Where do you define accounts?

1 Like

Not sure I understand the question. I deployed my contract on the local truffle develop, and I want to send some of the native test ether to my metamask account, so that I can interact with the smart contracts on the front end. Is this helpful?

1 Like

You’re getting this error because truffle doesn’t recognize accuonts[0] as a valid signer for the transaction. It is common to assign accounts with the output of web3.eth.getAccounts(), and I suspect you skipped that step. Hence my question: where do you define accounts?

1 Like

I dont understand why its not working, am following a udemy tutorial and its working just fine, at least for the tutor

1 Like

I already defined that in my App.js because my localhost webpage is loading ok
(Is this what you meant for me to confirm?)

1 Like

Or do I need to define the accounts variable to store the output of web3.eth.getAccounts() in the terminal first before trying to send that transaction?

1 Like

That’s right, truffle console’s execution context is isolated from your webapp, they’re two different programs. You have to define accounts in truffle console in order to reference it from there.

1 Like

Ok thanks let me give it a try

1 Like