How are strings serialized to byte arrays? I understand that they are treated like strings, and that ASCII (or utf8) encoding is used. But what about the rest of the bytes, what do they mean?

Running the LIGO CLI, I got:

$ ligo interpret -s pascaligo 'Bytes.pack(("Hello World!"))'

where the latter part, 48656c6c6f20576f726c6421 is simply the hexadecimal representation of the ASCII values of the string. But is the type and the length of the string also encoded somehow?

1 Answer 1


Strings are serialized as follows:

  1. 01 to indicate type string
  2. Four bytes (eight hex chars) to indicate length of string: 0000000c=0x0c=12 in your case
  3. The string represented by its ASCII values: 48656c6c6f20576f726c6421 in your case

The 05 in the beginning is a prefix which is only used by the PACK Michelson instruction which the Bytes.pack function in LIGO compiles down to.


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.