The payload tells the contract which function you want to call, and the respective argument values to execute that call.
Structure of a payload
A payload comprises of 2 main parts - the function selector and its argument values. Let's say you want to call a particular function in a specific contract:
This is how the payload is formed (and take note that the following are hex-serialized):
- The function selector - Take the first 4 bytes of the Keccak-256 hash of a string of the function along with the argument types. (e.g. the first 4 bytes of
transfer(address,uint256) gives you
- Argument values - Say you want to transfer to the address
0x337c67618968370907da31dAEf3020238D01c9de, and send
10000 tokens. You will need to pad these two values separately to 32 bytes, which will give you
0x0000000000000000000000000000000000000000000000008ac7230489e80000 respectively. Make sure that the tokens are in the correct units though (such as 1 Ether being equal to 10^18 wei).
Finally, remove all the
0x at the first 2 indices of each of the hex-encoded data above and concatenate them to form a giant string which gives you the following:
a9059cbb (from the hashed function signature) +
000000000000000000000000337c67618968370907da31dAEf3020238D01c9de (from the address argument) +
0000000000000000000000000000000000000000000000008ac7230489e80000 (from the uint256 amount of tokens sent argument).
Therefore, the data payload will be as follows:
This in itself is sufficient to tell a specific contract which function you're calling, and the values that are supplied to it as arguments.