Skip to main content

Serialization

Serialize data​

The expression Pack serializes any value of packable type to its optimized binary representation, of type TBytes().

const {
Contract,
EntryPoint,
SetValue,
ContractStorage,
None,
Some,
Pack,
TString,
} = require('@tezwell/smartts-sdk');

const contract = new Contract()
.setStorage(None())
.addEntrypoint(
new EntryPoint('entry_point_1')
.setInputType(TString())
.code((argument) => [
SetValue(ContractStorage(), Some(Pack(argument)))
]),
);

Deserialize data​

The expression Unpack deserialize a value of type TBytes() into the corresponding Michelson value of type TOption(...).

const {
Contract,
EntryPoint,
SetValue,
ContractStorage,
None,
Pack,
TBytes,
} = require('@tezwell/smartts-sdk');

const contract = new Contract()
.setStorage(None())
.addEntrypoint(
new EntryPoint('entry_point_1')
.setInputType(TBytes())
.code((argument) => [
SetValue(ContractStorage(), Unpack(argument))
]),
);