1

I know sendRawTransaction can send Ether to another account address. Now, I need to use sendRawTransaction to send Token to another account address. In sendRawTransaction, the param to should be the contract's address, but I don't know how to populate the param data nor how to tell the contract the target account address. Who can tell me? Thanks!

1

I assume you are working in the web3 console of, e.g. geth?

You need to first create an instance of that contract:

var contractInstance = web3.eth.contract(abi).at(address);

Now you can call the transfer function to send a defined amount of token from you account (e.g. account number 0) to the recipient account:

contractInstance.transfer(recipient, amount, {from: web3.eth.accounts[0], gas: 200000});

Make sure to send enough gas, the exact value depends on the token.

  • i use the web3js libhttps://github.com/web3j/web3j/blob/master/README.rst in Android client ,not the js function – user17314 Aug 26 '17 at 10:03
  • i know you means should use the contract instance to call the transfer custom function in contract replace the sendrawtransaction function ? – user17314 Aug 26 '17 at 10:07
  • 1
    Use contractInstance.transfer instead of sendrawtransaction if you can. – Validity Labs - Sebastian Aug 26 '17 at 11:40

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.