0

I got this event signature:

event Event(address indexed from, address indexed to, string text);

Which I call inside this method:

function emitEvent(address to, string calldata text) external {
    emit Event(msg.sender, to, text);
}

Once I call the function EmitEvent, the data field in logs appears to be split in three different pieces: logs screenschot

Topics are correct: the event signature and the from and to addresses.

However, the data field is divided in 3 instead of just one string (I sent the "Hello world" text as you can see). Where does the previous data information come from? The number 32 and 11?

Thank you!

1 Answer 1

0

Francesco,

Data layout here is the following:

  • slot0: 32 (0x20) is the data offset, basically this points to the
  • slot1 (each slot is 32 bytes long) slot1: 11 is the length of the string "Hello world" (actually underlying bytes array)
  • slot2: "Hello world" string (48 65 6C 6C 6F 20 77 6F 72 6C 64)

String is stored as a dynamic array and thus needs offset and length be present.

See also:

  1. Similar question, but here the string is stored in slot2, and the offset is 64 (0x40): can anyone explain the format of this input string to a function?
  2. https://docs.soliditylang.org/en/v0.8.21/abi-spec.html#use-of-dynamic-types

Note also that if the string contains non-ASCII characters, the length becomes bigger than just number of characters in the string, since some characters require more than 1 byte.

1
  • Thank you for pointing me in the right direction! Sep 14 at 19:10

Your Answer

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

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