2

If I pass in the string QmbPAr5RcCZZDRsNKnf2p1t6GK3Qu7oDH39HCK3aewUq3w to the sp.pack method in an entrypoint and perform and sp.trace in smartpy I expect to get the following bytes:

0x516d62504172355263435a5a4452734e4b6e663270317436474b335175376f4448333948434b3361657755713377

However, I receive the following bytes:

0x05010000002e516d62504172355263435a5a4452734e4b6e663270317436474b335175376f4448333948434b3361657755713377

You can see that the bytes 0x05010000002e are being prepended to the value during the pack

Why does this happen?

1 Answer 1

3

0x05 means "this is a packed Michelson value". 0x01 means "this is a string". The remaining 4 bytes represent the length of the string.

A complete description of the binary format of Michelson values can be generated by the following command: tezos-codec describe alpha.script.expr binary schema.

2
  • interesting.. thank you. do you know if it is possible to turn a string sent into an entrypoint into its raw bytes representation within the entrypoint? i thought sp.pack would do this, and while sp.utils.bytes_of_string gives the right answer it is only available at compile time
    – 0x10
    Jan 21 at 11:33
  • i expanded this comment into a full question: tezos.stackexchange.com/questions/4001/…
    – 0x10
    Jan 21 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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