0

I build, compiled and deployed (to Testrpc) the token contract from the cryptocurrency tutorial.

The token offers the transfer(addres _to, uint256 value) method, which I would like to call from coinbase in the node console.

> contractDeployed.transfer
{ [Function: bound ]
  request: [Function: bound ],
  call: [Function: bound ],
  sendTransaction: [Function: bound ],
  estimateGas: [Function: bound ],
  getData: [Function: bound ],
  'address,uint256': [Circular] }
> 
> 
> contractDeployed.transfer(web3.eth.accounts[1], 100)
Error: invalid address
    at inputAddressFormatter (/home/mzh/node_modules/web3/lib/web3/formatters.js:273:11)
    at inputTransactionFormatter (/home/mzh/node_modules/web3/lib/web3/formatters.js:99:20)
    at /home/mzh/node_modules/web3/lib/web3/method.js:89:28
    at Array.map (native)
    at Method.formatInput (/home/mzh/node_modules/web3/lib/web3/method.js:88:32)
    at Method.toPayload (/home/mzh/node_modules/web3/lib/web3/method.js:114:23)
    at Eth.send [as sendTransaction] (/home/mzh/node_modules/web3/lib/web3/method.js:139:30)
    at SolidityFunction.sendTransaction (/home/mzh/node_modules/web3/lib/web3/function.js:170:26)
    at SolidityFunction.execute (/home/mzh/node_modules/web3/lib/web3/function.js:256:37)
    at repl:1:18

What is wrong with the address of accounts[1]?

> web3.eth.accounts[1]
'0xf6efe9d4c094be73dd5b2137e1c34032a1ea88e3'

How else to execute the transfer?


I also tried the instructions from the TESTRPC helpfile to unlock accounts at startup:

mzh@~ $ node_modules/.bin/testrpc --secure -u 0 -u 1
EthereumJS TestRPC v4.1.3 (ganache-core: 1.1.3)

Available Accounts
==================
(0) 0x0e7088e20e8d7e23a2ec6704104fbcc0e6c61845
(1) 0xa27b21423aeab486b0eb9d24d36dc354813754ce
(2) 0x6769222c45b93ca010b911842f893b8f3c862f25 🔒
(3) 0xe4dcd88080804ea5f047fabe609dd8236090f75c 🔒
(4) 0xca26648402c7446179d9d76fbc736f817d43f9fe 🔒

Clearly, accounts 0 and 1 are unlocked from the start. Still, I can't transfer from account 0 to 1.

> contractDeployed.transfer(web3.eth.accounts[1], 100)
Error: Error: could not unlock signer account
    at StateManager.queueTransaction (/home/mzh/node_modules/ethereumjs-testrpc/build/cli.node.js:83073:21)
    at GethApiDouble.eth_sendTransaction (/home/mzh/node_modules/ethereumjs-testrpc/build/cli.node.js:82631:14)

I got the inspiration for the solution from this question.

The call to transfer requires an additional, implicit argument

> contractDeployed.transfer(web3.eth.accounts[1], 100, {from: web3.eth.accounts[0]})
'0xcc2dda4270217201989495abfc3a9953ebfb8f51b81dbcb80e3aec52d7e225bb'
0

Try eth.defaultAccount = web3.eth.accounts[1] or personal.unlockAccount(web3.eth.accounts[1]) Or both.

  • I tried it, but I get a very strange error which I can not understand – TMOTTM Nov 1 '17 at 10:04
  • Really strange but actually i use all the commangs that you do but without preceeding web3. Can you try all the same with no web3. prefix? – ITisha Nov 1 '17 at 10:23
  • I work in the node console, not the geth console. it needs web3. prepended. – TMOTTM Nov 1 '17 at 10:24
  • I found the solution, see edited question. – TMOTTM Nov 1 '17 at 10:53
0

If you want to transfer ether from one account to another account, you can use this:

web3.eth.sendTransaction({from:web3.eth.accounts[0],to:web3.eth.accounts[1],value:1})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.