Contract Invocation – Understanding What Calldata Is

abicalldatacontract-invocation

What is calldata? I learned that there are three types of memories:

  1. Storage
  2. Memory
  3. Stack

In the Ethereum docs, it says that the function parameters are of type memory by default.

However, I've also read an article which said that function arguments are stored in calldata.

Now, I don't know what calldata is, can somebody please help me?

Thanks!

Best Answer

Here is an example from What is an ABI and why is it needed to interact with contracts?

contract Foo {
  function baz(uint32 x, bool y) returns (bool r) { r = x > 32 || y; }
}

If we wanted to call baz() with the parameters 69 and true, we would pass 68 bytes in total, which can be broken down into:

0xcdcd77c0: the Method ID. This is derived as the first 4 bytes of the Keccak-256 hash of the ASCII form of the signature baz(uint32,bool). 0x0000000000000000000000000000000000000000000000000000000000000045: the first parameter, a uint32 value 69 padded to 32 bytes. (69 is hex 0x45.) 0x0000000000000000000000000000000000000000000000000000000000000001: the second parameter - boolean true, padded to 32 bytes

The 68 bytes is the calldata: 0xcdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001.

Related Topic