I am trying to follow a tutorial available at: medium Just Dev
> getBalance = web3.eth.getBalance
> balanceInEth = address => web3.fromWei(getBalance(address).toString())
I got errors so I used the following command:
> getBalance = web3.eth.getBalance;"Testing"
'Testing'
truffle(development)> balanceInEth = async(address) => web3.utils.fromWei(await web3.eth.getBalance(address))
But they are generating huge error:
Thrown: TypeError: Cannot read property 'match' of undefined at ReadStream.onData (readline.js:1073:36) at emitKeys.next () at emitKeys (internal/readline.js:424:14) at ReadStream.EventEmitter.emit (domain.js:448:20) at ReadStream.emit (events.js:198:13)
I was told to use following command at:
Error Truffle Console: web3.fromWei is not a function
truffle(ganache)> web3.eth.getAccounts(function(err, acc) { accounts = acc });
truffle(ganache)> const boo = async () => { return web3.utils.fromWei(await web3.eth.getBalance(accounts[0]), 'ether'); }
truffle(ganache)> boo()
'99.0015542'
The above commands are printing the account values for acc1, victim and attacker but when I am executing the transaction for victim, I am getting a huge error message:
truffle(development)> options = { from: acc1, to : victim.address,
value: web3.utils.toWei('11', 'ether')}
{ from: [AsyncFunction: acc1], to: '0xA3339bb424303D6F58B1260872c9C2DBF840e771', value: '11000000000000000000' }
truffle(development)> victim.deposit.sendTransaction(options)
Thrown: { Error: Returned error: from not found; is required at evalmachine.:0:16 at sigintHandlersWrap (vm.js:288:15) at Script.runInContext (vm.js:130:14) at runScript (/home/zulfi/.nvm/versions/node/v10.22.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:227:1)
Somebody please guide me how to print account values on truffle console.
Zulfi.