with this code i want to call my token smartcontract's transfer function. as per my knowledge i have to add this ".transfer(address,amount)" to data field. am i correct? also i am using web3 0.20. in this version i have to use getData right? so that will be var dataforTx = mycontract.tranfer.getData(address,amount); then add that dataforTx to data field?

var Tx = require('ethereumjs-tx'); var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')

var rawTx = { nonce: '0x00', gasPrice: '0x09184e72a000',
gasLimit: '0x2710', to: '0x0000000000000000000000000000000000000000', value: '0x00',
****data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057' }** //how to get hex value of my dataforTx????????**

var tx = new Tx(rawTx); tx.sign(privateKey);

var serializedTx = tx.serialize();


web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) { if (!err) console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385" });

i am still not able to transfer token.it returns hash value but not reflecting any balance in other account. and if i use balanceOf then how to catch output of balanceOf function in sendRawTransaction


2 Answers 2

var abi=[//your abi array];

var contractAddress = "//your contract address";

var contract = web3.eth.contract(abi).at(contractAddress);

let send_add = data.send_public_address;

let recv_add = rec_public_address;

let amount = web3.toHex(transfer_amount),

let nonce = web3.toHex(web3.eth.getTransactionCount(send_public_address));

var private_key = privatekey_sender.slice(2);

let gas = web3.toHex(data.gas_limit);

let gasPrice = web3.toHex(data.gas_price);

var rawTx = {

        from: send_add,

        nonce: nonce,

        gasLimit: gas,

        gasPrice: gasPrice,

        amount: web3.toHex(transfer_amount),

        to: recv_add,


var transaction = new tx(rawTx);

var txData = new Buffer(private_key, 'hex');


var serializedTx = transaction.serialize().toString('hex');

contract.transfer.sendTransaction(recv_add , amount , {'0x' + serializedTx}, 
function (err, txHash) {

        if (txHash) {

            next(null, txHash);


        else if (err && err.message) {

            next(err.message, null);


        else {

            next('Unable to sendTransaction', null);


  • Can you add an explanation how this answer the question?
    – Ismael
    Sep 4, 2018 at 16:17

Here I made a tutorial for this problem https://github.com/pubkey/eth-crypto/blob/master/tutorials/signed-data.md#deploy-the-contract

  • Link only answer are not recommended because they become useless if the server is down or the page is moved. It is better to include the main points in the answer and only use the link to expand on the details.
    – Ismael
    Dec 31, 2018 at 11:41

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