[Ethereum] Ethereum transaction binary data field

raw-transactiontransactions

There are a few questions on creating transactions and signing them offline using ethereumjs-tx. What I'm interested in is how do we build the binary data field based on the desired functionality.
E.g. what is the binary data equivalent of 'execute method1 with 'foo' and 7 as arguments'?

I was planning on creating a transaction to do what I want using web3 and just stealing the bytecode from that, but it seems hacky. Any suggestions would be much appreciated!

Best Answer

Stepping into the web3 javascript functions when sending a transaction yielded some insight. Turns out the data field is made up of the following:

  • The signature of the method. This is obtained by doing a sha3 (256 bit by the looks of it) on the hex-encoded method prototype and truncating it to 8 characters.
  • The arguments to the method. These are just converted to hex format.

Both of the above are serialised into a single buffer.

From that, you could build your own transaction data using the method prototype (e.g. myMethod(uint8,uint16)).

Related Topic