1

I am using the tezos-sandbox cli and trying out packing/unpacking data. I want to try doing the equivalent of sp.unpack(x, t = …​), specifying a type to unpack into, using the command

tezos-client unpack michelson data 0x050a0000002071f0fcd58b7d488e6bf571facc72baf5ce2ef2bb79e2fd97d2e82fdb9c351f1c

I was expecting something like

tezos-client unpack michelson data 0x050a... of type mutez

or something like that?

2

There are two concepts to distinguish to understand why UNPACK requires a type in Michelson (and SmartPy) but the tezos-client unpack michelson data does not: serialization and type-checking.

Serialization is the process of converting a tree-like structure into a linear representation. In our case the tree-like structure is Micheline and the linear representation is a sequence of bytes (usually written in hexadecimal notation with the 0x prefix). Deserialization is, as the name suggests, the opposite transformation from byte sequences to Micheline.

Type-checking is the process by which we filter nonsensical expressions. The input of the Michelson type checker is Micheline. An important invariant of the Michelson interpreter is that the data manipulated on the Michelson stack is always well-typed.

The UNPACK Michelson instruction does both deserialization and type checking. If either fails, it returns None. The type argument of the UNPACK instruction is only used for the type-checking part of the job.

The tezos-client unpack michelson data command does only deserialization; it returns a Micheline node that may or not be well-typed.

To type-check the Micheline node produced by the tezos-client unpack michelson data command, you need another command: tezos-client typecheck data ... against type ....

1
  • Ah okay that makes sense. Thanks! – Darius Oct 27 '20 at 16:27

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.