1

Previously when I asked about converting types, I got this useful suggestion:

For mutez, you could start to convert to int (by dividing by 1 mutez) and then use the same techniques.

I'm wondering if there are any similar tricks specifically to go from mutez to bytes, or int to bytes. Ideally tricks for doing so that can be done in SmartPy.

0

1 Answer 1

1

You can use sp.pack on expressions of most regular types. It computes a serialized representation of your data.

3
  • Ah okay great. This almost works except would it be possible to have the number be in hex representation? e.g. converting 255 into 0xFF? Right now using pack on 255 I get 0x0500bf03
    – Darius
    Oct 21, 2020 at 15:04
  • or if not, is there documentation to describe the steps to get to the serialization?
    – Darius
    Oct 21, 2020 at 15:36
  • 1
    There is this other question dealing with the format. tezos.stackexchange.com/questions/612/…. I don't think there is a way to get 0xFF from 255 without coding it in exactly the same way you can code pretty-printers.
    – FFF
    Oct 21, 2020 at 17:21

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.