Cells, Builders and Slices
Cells is a low level primitive that represents data in TON blockchain. Cell consists of a 1023 bits of data with up to 4 references to another Cells. Cells are read-only and immutable. Builders are immutable structures that can be used to construct Cells. Slices are a way to parse cells.
beginCell
fun beginCell(): Builder
Creates a new empty Builder.
Builder.endCell
extends fun endCell(self: Builder): Cell;
Extension function for the Builder.
Converts a Builder into an ordinary Cell.
Builder.storeUint
extends fun storeUint(self: Builder, value: Int, bits: Int): Builder;
Extension function for the Builder.
Stores an unsigned bits
-bit Int value
into the Builder for . Returns modified Builder.
Builder.storeInt
extends fun storeInt(self: Builder, value: Int, bits: Int): Builder;
Extension function for the Builder.
Stores a signed bits
-bit Int value
into the Builder for . Returns modified Builder.
Builder.storeBool
extends fun storeBool(self: Builder, value: Bool): Builder;
Extension function for the Builder.
Stores a Bool value
into the Builder. Writes -1
if value
is true
, and writes 0
otherwise. Returns modified Builder.
Builder.storeSlice
extends fun storeSlice(self: Builder, cell: Slice): Builder;
Extension function for the Builder.
Stores a Slice cell
into the Builder. Returns modified Builder.
Builder.storeCoins
extends fun storeCoins(self: Builder, value: Int): Builder;
Extension function for the Builder.
Stores (serializes) an integer value
in the range into the Builder. The serialization of value
consists of a 4-bit unsigned big-endian integer , which is the smallest integer , such that value
, followed by an -bit unsigned big-endian representation of value
. If value
does not belong to the supported range, a range check exception is thrown. Returns modified Builder.
This is the most common way of storing Toncoins.
Builder.storeAddress
extends fun storeAddress(self: Builder, address: Address): Builder;
Extension function for the Builder.
Stores Address address
in the Builder. Returns modified Builder.
Builder.storeRef
extends fun storeRef(self: Builder, cell: Cell): Builder;
Extension function for the Builder.
Stores a reference Cell cell
into the Builder. Returns modified Builder.
Builder.refs
extends fun refs(self: Builder): Int;
Extension function for the Builder.
Returns the number of cell references already stored in the Builder as an Int.
Builder.bits
extends fun bits(self: Builder): Int;
Extension function for the Builder.
Returns the number of data bits already stored in the Builder as an Int.
Builder.asSlice
extends fun asSlice(self: Builder): Slice;
Extension function for the Builder.
Converts the Builder to a Slice. Alias to self.endCell().beginParse()
.
Builder.asCell
extends fun asCell(self: Builder): Cell;
Extension function for the Builder.
Converts the Builder to a Cell. Alias to self.endCell()
.
Cell.beginParse
extends fun beginParse(self: Cell): Slice;
Extension function for the Cell.
Opens the Cell for parsing and returns it as a Slice.
Cell.hash
extends fun hash(self: Cell): Int;
Extension function for the Cell.
Calculates hash of the Cell as an Int.
Cell.asSlice
extends fun asSlice(self: Cell): Slice;
Extension function for the Cell.
Converts the Cell to a Slice. Alias to self.beginParse()
.
Slice.loadInt
extends mutates fun loadInt(self: Slice, l: Int): Int;
Extension mutation function for the Slice.
Loads a signed l
-bit Int from the Slice.
Slice.preloadInt
extends mutates fun preloadInt(self: Slice, l: Int): Int;
Extension mutation function for the Slice.
Preloads a signed len
-bit Int from the Slice.
Slice.loadUint
extends mutates fun loadUint(self: Slice, l: Int): Int;
Extension mutation function for the Slice.
Loads an unsigned l
-bit Int from the Slice.
Slice.preloadUint
extends mutates fun preloadUint(self: Slice, l: Int): Int;
Extension mutation function for the Slice.
Preloads an unsigned l
-bit Int from the Slice.
Slice.loadBits
extends mutates fun loadBits(self: Slice, l: Int): Slice;
Extension mutation function for the Slice.
Loads the first bits from the Slice, and returns it as a separate Slice.
Slice.preloadBits
extends mutates fun preloadBits(self: Slice, l: Int): Slice;
Extension mutation function for the Slice.
Preloads the first bits from the Slice, and returns it as a separate Slice.
Slice.loadCoins
extends mutates fun loadCoins(self: Slice): Int;
Extension mutation function for the Slice.
Loads serialized amount of nanoToncoins (any unsigned integer up to ) as an Int.
Slice.loadAddress
extends mutates fun loadAddress(self: Slice): Address;
Extension mutation function for the Slice.
Loads an Address from the Slice.
Slice.loadRef
extends mutates fun loadRef(self: Slice): Cell;
Extension mutation function for the Slice.
Loads the first reference from the Slice as a Cell.
Slice.refs
extends fun refs(self: Slice): Int;
Extension function for the Slice.
Returns the number of references in the Slice as an Int.
Slice.bits
extends fun bits(self: Slice): Int;
Extension function for the Slice.
Returns the number of data bits in the Slice as an Int.
Slice.empty
extends fun empty(self: Slice): Bool;
Extension function for the Slice.
Checks whether the Slice is empty (i.e., contains no bits of data and no cell references). Returns true
if it's empty, false
otherwise.
Slice.dataEmpty
extends fun dataEmpty(slice: Slice): Bool;
Extension function for the Slice.
Checks whether the Slice has no bits of data. Returns true
if it has no data, false
otherwise.
Slice.refsEmpty
extends fun refsEmpty(slice: Slice): Bool;
Extension function for the Slice.
Checks whether the Slice has no references. Returns true
if it has no references, false
otherwise.
Slice.hash
extends fun hash(self: Slice): Int;
Extension function for the Slice.
Calculates hash of the Slice as an Int.
Slice.asCell
extends fun asCell(self: Slice): Cell;
Extension function for the Slice.
Converts the Slice to a Cell. Alias to beginCell().storeSlice(self).endCell()
.
emptyCell
fun emptyCell(): Cell;
Creates and returns an empty Cell (without data and references). Alias to beginCell().endCell()
.