Better question: Can I send the bytes to a function that lacks this definition?

In other words, say I have:

 event Transfer(address,address,uint256, bytes);

And then:

function transfer(msg.sender, address _to,uint _value, msg.data) {}

In msg.data I could frame the whole transaction message (who to, how much...) in just string of bytes - yet what if I don't have this and it's just the classic ERC20:

function transfer(msg.sender, address _to,uint _value) {}

Does this mean I can use web3 to simply put a string of bytes under "data"??


// pseudo string of bytes of: function + address + amount:
var send_data_as_bytes = '030300x0x0' + '0x0000000000000000000000' + 000000001';
// prepare the transaction: 
'from': fromAddress,
      'gasPrice': Web3js.utils.toHex(20 * 1e9),
      'gasLimit': Web3js.utils.toHex(210000),
      'to': tokenAddress,
      'value': 0x0,
      'data': send_data_as_bytes,
      'nonce': Web3js.utils.toHex(count)

1 Answer 1


A contract call is simply a regular transaction where the to address is the contract address and the data field contains the encoded method and parameters.

  • thanks, everything worked...except not as expected :). I can send any string of bytes to ropsten at least but the ether gets transfered from address to another address - I just wanted it transfered to the contract? So when I call balanceOf t - the balance is "0" but only according to the contract, yet the address receiver has received ether and now has positive balance...go figure...not my original intention.
    – Robert Ggg
    Nov 5, 2019 at 14:27
  • This all depend on the code of the contract. Some contract can receive ether and keep it, some others can transfer the ether they receive. And transferring ERC20 is very different.
    – Kivutar
    Nov 6, 2019 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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