We've finally reached the point we've been working toward for the past six months: automatic (de)serialization of anything into cells. From simple structs to unions, generics, and even nested references β it just works.
The goal? To replace TL/B entirely with declarative, type-safe definitions. The compiler takes care of packing, loading, estimating, error handling, and more.
β Notable changes in Tolk v0.13:
1. Auto-packing to/from cells/slices/builders
2. Type
address3. Lateinit variables, default parameters, and other minor features
PR on GitHub with detailed info.
β Auto-serialization: short demo
struct Point {
x: int8;
y: int8;
}
var value: Point = { x: 10, y: 20 };
// makes a cell containing "0A14"
var c = value.toCell();
// back to { x: 10, y: 20 }
var p = Point.fromCell(c);
Key features:
* supports all types: unions, tensors, nullables, generics, atomics, ...
* allows to specify prefixes (particularly, opcodes)
* allows to manage cell references and when to load them
* lets you control error codes and other behavior
* unpacks data from a cell or a slice, mutate it or not
* packs data to a cell or a builder
* warns if data potentially exceeds 1023 bits
* more efficient than manual serialization
* will seamlessly integrate with message sending/receiving in Tolk v1.0
β Pack or unpack β anywhere
T.fromCell, T.fromSlice, slice.loadAny<T>, builder.storeAny<T>, and other methods give both high-level and low-level API.
// low-level is allowed:
beginCell()
.storeUint(1, 32) // mix manual
.storeAny(myStruct) // with auto
β Serialization prefixes and opcodes
struct (0x7362d09c) TransferNotification {
queryId: uint64;
...
}
They are not limited to 32 bits β you can describe any TL/B constructors:
struct (0b001) AssetSimple { ... }
struct (0b100) AssetBooking { ... }
type Asset = AssetSimple | AssetBooking | ...;
β Typed cells
struct A {
ref1: cell; // untyped ref
ref2: Cell<Inner>; // typed ref
ref3: Cell<int256>?; // maybe ref
}
Typed cells give you full control over when content is unpacked β nothing is loaded unless you call .load() manually:
a.ref2.field // error
a.ref2.load().field // ok
// Yes,
point.toCell() really gives you Cell<Point>β Granular options
Accurately adjust serialization behaviour (for example, error codes):
Point.fromSlice(s, {
assertEndAfterReading: false
})
β Built-in type `address`
struct Wallet {
owner: address;
}
* integrated with auto-serialization, while still a slice under the hood
* comparable:
if (senderAddress == wallet.owner)* introspectable: isInternal(), getWorkchain(), etc.
β Some other features
Described in detail in the full changelog and mirrored in the documentation.
π³ We're just a couple of steps away from Tolk v1.0 β with message sending and handling, gas optimizations, and one secret feature. There is still a lot of work ahead, but today we're closer to the release than ever before.