Micheline
Smart contract data encoding and transformation
Visit the Go Doc docu or read the source code on Github.
Tezos uses Micheline for encoding smart contract data and code. Micheline is strongly typed, but complex and has a few ambiguities that make it hard to use. TzGo contains a library that lets you easily decode, analyze and construct compliant Micheline data structures from Go types.
Primitives
Micheline uses basic primitives (Prim
) for encoding types and values. These primitives can be expressed in JSON and binary format and TzGo can translate between them efficiently. Micheline also supports type annotations which are used by high-level languages to express complex data types like records and their field names.
TzGo defines a basic Prim
data type to work with Micheline primitives directly:
Since Micheline value encoding is quite verbose and can be ambiguous, TzGo supports unfolding of raw Micheline using helpers Value
and Type
with member functions like Map()
, GetInt64()
, GetAddress()
:
Type
is a TzGo wrapper for simple or complex primitives which contain annotated type infoValue
is a TzGo wrapper for simple or complex primitives representing Micheline values in combination with their TypeKey
is a TzGo wrapper for special comparable values that are used as map or bigmap keys
Sometimes Micheline values have been packed into byte sequences with the Michelson PACK instruction and it is desirable to unpack them before processing (e.g. to retrieve UFT8 strings or nested records). TzGo supports Unpack()
and UnpackAll()
functions on primitives and values and also detects the internal type of packed data which is necessary for unfolding.
Value API
Micheline type and value trees are verbose and can be ambiguous due to comb-pair optimizations. If you don't know or don't care about what that even means, you may want to use the Value
API which helps you translate Micheline into human readable form.
There are multiple options to access decoded data:
Last updated