---
title: Cells, Builders and Slices
description: "Various Cell, Builder, and Slice functions from the Core library of Tact"
---

import { Badge } from '@astrojs/starlight/components';

[`Cell{:tact}`][cell] is a low-level [primitive][p] that represents data in TON Blockchain. Cells consist of $1023$ bits of data with up to $4$ references to other cells. They are read-only and immutable, and cannot have cyclic references.

[`Builder{:tact}`][builder] is an immutable [primitive][p] to construct cells, and [`Slice{:tact}`][slice] is a mutable [primitive][p] to parse them.

:::note

  Be very careful when constructing and parsing cells manually, and always make sure to document their desired layout: a strict order of values and types for serialization and deserialization.

  To do so, advanced users are recommended to use [Type Language - Binary (TL-B) schemas][tlb].

  Additionally, every user is recommended to use [structs][struct] and their [methods](/book/functions#extensions), such as [`Struct.toCell(){:tact}`](#structtocell) and [`Struct.fromCell(){:tact}`](#structfromcell), instead of manually constructing and parsing cells, because structs and [Messages][message] are closest to being the [living TL-B schemas of your contracts](/book/cells#cnp-structs).

:::

## beginCell

```tact
fun beginCell(): Builder;
```

Creates a new empty [`Builder{:tact}`][builder].

Usage example:

```tact
let fizz: Builder = beginCell();
```

## emptyCell

```tact
fun emptyCell(): Cell;
```

Creates and returns an empty [`Cell{:tact}`][cell] (without data and references). An alias to `beginCell().endCell(){:tact}`.

Usage example:

```tact
let fizz: Cell = emptyCell();
let buzz: Cell = beginCell().endCell();

fizz == buzz; // true
```

## emptySlice

```tact
fun emptySlice(): Slice;
```

Creates and returns an empty [`Slice{:tact}`][slice] (without data and references). An alias to `emptyCell().asSlice(){:tact}`.

Usage example:

```tact
let fizz: Slice = emptySlice();
let buzz: Slice = emptyCell().asSlice();

fizz == buzz; // true
```

## Cell

A section to group all extension and extension mutation functions for the [`Cell{:tact}`][cell] type.

### Cell.beginParse

```tact
extends fun beginParse(self: Cell): Slice;
```

Extension function for the [`Cell{:tact}`][cell] type.

Opens the [`Cell{:tact}`][cell] for parsing and returns it as a [`Slice{:tact}`][slice].

Usage example:

```tact
let c: Cell = emptyCell();
let fizz: Slice = c.beginParse();
```

### Cell.depth

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun depth(self: Cell?): Int;
```

Extension function for the [`Cell{:tact}`][cell] type.

Computes and returns the [`Int{:tact}`][int] [depth][std-repr] of the [`Cell{:tact}`][cell]. Produces $0$ if the [`Cell{:tact}`][cell] has no references. Otherwise, it returns $1$ plus the maximum of the depths of the referenced cells. If `self{:tact}` is [`null{:tact}`][null], returns $0$.

Usage example:

```tact
let c: Cell = beginCell().storeInt(42, 7).endCell();
let depth: Int = c.depth(); // 0
```

### Cell.computeDataSize

<Badge text="500+ gas" title="Uses 500 gas units or more" variant="danger" size="medium"/>
<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun computeDataSize(self: Cell?, maxCells: Int): DataSize;
```

Extension function for the [`Cell{:tact}`][cell] type.

Computes and returns the number of distinct cells, bits, and refs in the [`Cell{:tact}`][cell] by using a [depth-first search (DFS)][dfs] algorithm, recursively traversing each referenced cell. This function is computationally expensive and can consume a lot of [gas][gas]. If `self{:tact}` is [`null{:tact}`][null], returns a `DataSize{:tact}` with all fields set to $0$.

The results are packed into a `DataSize{:tact}` [struct][struct] consisting of:

Field   | Type                | Description
:------ | :------------------ | :----------
`cells` | [`Int{:tact}`][int] | The total number of nested cells, including the starting one
`bits`  | [`Int{:tact}`][int] | The total number of bits in all nested cells, including the starting one
`refs`  | [`Int{:tact}`][int] | The total number of refs in all nested cells, including the starting one

If the specified `maxCells` value is insufficient to traverse all cells including the starting one, an exception with [exit code 8](/book/exit-codes#8) is thrown: `Cell overflow`.

Attempts to specify a negative value for `maxCells` throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Usage example:

```tact
let c: Cell = beginCell().storeInt(42, 7).storeRef(emptyCell()).endCell();
try {
    let dataSize: DataSize = c.computeDataSize(2);
    dataSize.cells; // 2
    dataSize.bits;  // 7
    dataSize.refs;  // 1
} catch (exitCode) {
    // if maxCells was insufficient to traverse the cell
    // and all of its references, the exitCode here would be 8
}
```

### Cell.hash

```tact
extends fun hash(self: Cell): Int;
```

Extension function for the [`Cell{:tact}`][cell] type.

Calculates and returns an [`Int{:tact}`][int] value of the [SHA-256][sha-2] hash of the [standard `Cell{:tact}` representation][std-repr] of the given [`Cell{:tact}`][cell].

Usage example:

```tact
let c: Cell = emptyCell();
let fizz: Int = c.hash();
```

### Cell.asSlice

```tact
extends fun asSlice(self: Cell): Slice;
```

Extension function for the [`Cell{:tact}`][cell] type.

Converts the Cell to a [`Slice{:tact}`][slice] and returns it. An alias to `self.beginParse(){:tact}`.

Usage example:

```tact
let c: Cell = emptyCell();
let fizz: Slice = c.asSlice();
```

## Builder

A section to group all extension and extension mutation functions for the [`Builder{:tact}`][builder] type.

### Builder.endCell

<Badge text="500+ gas" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>

```tact
extends fun endCell(self: Builder): Cell;
```

Extension function for the [`Builder{:tact}`][builder] type.

Converts a [`Builder{:tact}`][builder] into an ordinary [`Cell{:tact}`][cell].

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Cell = b.endCell();
```

### Builder.storeUint

```tact
extends fun storeUint(self: Builder, value: Int, bits: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores an unsigned `bits`-bit `value` into the copy of the [`Builder{:tact}`][builder] for 0 ≤ `bits` ≤ 256. Returns that copy.

Attempts to store a negative `value` or provide an insufficient or out-of-bounds `bits` number throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeUint(42, 6);
```

### Builder.storeInt

```tact
extends fun storeInt(self: Builder, value: Int, bits: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores a signed `bits`-bit `value` into the copy of the [`Builder{:tact}`][builder] for 0 ≤ `bits` ≤ 257. Returns that copy.

Attempts to provide an insufficient or out-of-bounds `bits` number throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeInt(42, 7);
```

### Builder.storeBool

```tact
extends fun storeBool(self: Builder, value: Bool): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores a [`Bool{:tact}`][bool] `value` into the copy of the [`Builder{:tact}`][builder]. Writes 1 as a single bit if `value` is `true{:tact}`, and writes 0 otherwise. Returns that copy of the [`Builder{:tact}`][builder].

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeBool(true);  // writes 1
let buzz: Builder = b.storeBool(false); // writes 0
```

### Builder.storeBit

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
extends fun storeBit(self: Builder, value: Bool): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

An alias to [`Builder.storeBool(){:tact}`](#builderstorebool).

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeBit(true);  // writes 1
let buzz: Builder = b.storeBit(false); // writes 0
```

### Builder.storeBuilder

```tact
extends fun storeBuilder(self: Builder, other: Builder): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Appends all data from the `other` builder to the copy of the `self` builder. Returns that copy.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
fun example(op: Int, queryId: Int, payload: Builder) {
   let msgBody = beginCell().storeUint(op, 32).storeUint(queryId, 64);
   if (payload.bits() != 0) {
       msgBody = msgBody.storeBuilder(payload); // assignment is important here
   }
}
```

### Builder.storeSlice

```tact
extends fun storeSlice(self: Builder, slice: Slice): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores a `slice` into a copy of the [`Builder{:tact}`][builder]. Returns that copy.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let s: Slice = emptyCell().asSlice();
let fizz: Builder = b.storeSlice(s);
```

### Builder.storeCoins

```tact
extends fun storeCoins(self: Builder, value: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores (serializes) an unsigned [`Int{:tact}`][int] `value` in the range from $0$ to $2^{120}-1$ inclusive into a copy of the [`Builder{:tact}`][builder]. The serialization of `value` consists of a $4$-bit unsigned big-endian integer $l$, which is the smallest integer $l ≥ 0$ such that `value` $< 2^{8 * l}$, followed by an $8 * l$-bit unsigned big-endian representation of `value`. Returns that copy of the [`Builder{:tact}`][builder].

Attempts to store an out-of-bounds `value` throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

This is the most common way of storing [nanoToncoins](/book/integers#nanotoncoin).

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeCoins(42);
```

:::note[Useful links:]

  [Special `coins{:tact}` serialization type](/book/integers#serialization-varint)

:::

### Builder.storeVarUint16

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun storeVarUint16(self: Builder, value: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

An alias to [`Builder.storeCoins(){:tact}`](#builderstorecoins).

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeVarUint16(42);
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Builder.storeVarInt16

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun storeVarInt16(self: Builder, value: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Similar to [`Builder.storeCoins(){:tact}`](#builderstorecoins), but with a different `value` range: from $-2^{119}$ to $2^{119}-1$ inclusive.

Attempts to store an out-of-bounds `value` throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeVarInt16(-42);
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Builder.storeVarUint32

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun storeVarUint32(self: Builder, value: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores (serializes) an unsigned [`Int{:tact}`][int] `value` in the range from $0$ to $2^{248}-1$ inclusive into a copy of the [`Builder{:tact}`][builder]. The serialization of `value` consists of a $5$-bit unsigned big-endian integer $l$, which is the smallest integer $l ≥ 0$ such that `value` $< 2^{8 * l}$, followed by an $8 * l$-bit unsigned big-endian representation of `value`. Returns that copy of the [`Builder{:tact}`][builder].

Attempts to store an out-of-bounds `value` throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeVarUint32(420000);
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Builder.storeVarInt32

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun storeVarInt32(self: Builder, value: Int): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Similar to [`Builder.storeVarUint32(){:tact}`](#builderstorevaruint32), but with a different `value` range: from $-2^{247}$ to $2^{247} - 1$ inclusive.

Attempts to store an out-of-bounds `value` throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeVarInt32(-420000);
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Builder.storeAddress

```tact
extends fun storeAddress(self: Builder, address: Address): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores the `address` in a copy of the [`Builder{:tact}`][builder]. Returns that copy.

Attempts to store an `address` into the [`Builder{:tact}`][builder] `self{:tact}`, if `self{:tact}` cannot fit it, throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeAddress(myAddress());
```

### Builder.storeBasechainAddress

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun storeBasechainAddress(self: Builder, address: BasechainAddress): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores the basechain `address` in the copy of the [`Builder{:tact}`][builder] and returns that copy.

If the address has a `null{:tact}` hash, stores two zero bits `0b00` (`addr_none`). Otherwise, stores the full address with the three-bit prefix `0b100`, followed by the 8-bit workchain ID set to 0 and the 256-bit hash.

Attempts to store more data than the [`Builder{:tact}`][builder] `self{:tact}` can fit throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
fun example() {
    let addr: BasechainAddress = newBasechainAddress(0x83dfd552e63729b472fcbcc8c45ebcc6691702558b68ec7527e1ba403a0f31a8);
    let b: Builder = beginCell();
    let b2: Builder = b.storeBasechainAddress(addr);
}
```

### Builder.storeRef

```tact
extends fun storeRef(self: Builder, cell: Cell): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

Stores a reference `cell` into a copy of the [`Builder{:tact}`][builder]. Returns that copy.

As a single [`Cell{:tact}`][cell] can store up to $4$ references, attempts to store more throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b.storeRef(emptyCell());
```

### Builder.storeMaybeRef

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
extends fun storeMaybeRef(self: Builder, cell: Cell?): Builder;
```

Extension function for the [`Builder{:tact}`][builder] type.

If the `cell` is not `null{:tact}`, stores $1$ as a single bit and then a reference to `cell` into a copy of the [`Builder{:tact}`][builder]. Returns that copy.

If the `cell` is `null{:tact}`, stores only $0$ as a single bit into the copy of the [`Builder{:tact}`][builder]. Returns that copy.

As a single [`Cell{:tact}`][cell] can store up to $4$ references, attempts to store more throw an exception with [exit code 8](/book/exit-codes#8): `Cell overflow`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Builder = b
    .storeMaybeRef(emptyCell()) // stores a single 1 bit, then an empty cell
    .storeMaybeRef(null);       // stores only a single 0 bit
```

### Builder.refs

```tact
extends fun refs(self: Builder): Int;
```

Extension function for the [`Builder{:tact}`][builder] type.

Returns the number of cell references already stored in the [`Builder{:tact}`][builder] as an [`Int{:tact}`][int].

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Int = b.refs(); // 0
```

### Builder.bits

```tact
extends fun bits(self: Builder): Int;
```

Extension function for the [`Builder{:tact}`][builder] type.

Returns the number of data bits already stored in the [`Builder{:tact}`][builder] as an [`Int{:tact}`][int].

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Int = b.bits(); // 0
```

### Builder.depth

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun depth(self: Builder): Int;
```

Extension function for the [`Builder{:tact}`][builder] type.

Computes and returns the [`Int{:tact}`][int] [depth][std-repr] of the [`Builder{:tact}`][builder]. Produces $0$ if the [`Builder{:tact}`][builder] has no references stored so far, otherwise $1$ plus the maximum depth of the referenced cells.

Usage example:

```tact
let b: Builder = beginCell().storeInt(42, 7);
let depth: Int = b.depth(); // 0
```

### Builder.asSlice

```tact
extends fun asSlice(self: Builder): Slice;
```

Extension function for the [`Builder{:tact}`][builder] type.

Converts the [`Builder{:tact}`][builder] into a [`Slice{:tact}`][slice] and returns it. An alias to `self.endCell().beginParse(){:tact}`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Slice = b.asSlice();
```

### Builder.asCell

```tact
extends fun asCell(self: Builder): Cell;
```

Extension function for the [`Builder{:tact}`][builder] type.

Converts the [`Builder{:tact}`][builder] into a [`Cell{:tact}`][cell] and returns it. An alias to `self.endCell(){:tact}`.

Usage example:

```tact
let b: Builder = beginCell();
let fizz: Cell = b.asCell();
```

## Slice

A section to group all extension and extension mutation functions for the [`Slice{:tact}`][slice] type.

### Slice.loadUint

```tact
extends mutates fun loadUint(self: Slice, l: Int): Int;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads and returns an unsigned `l`-bit [`Int{:tact}`][int] from the [`Slice{:tact}`][slice], for $0 ≤ l ≤ 256$.

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeUint(42, 7).asSlice();
let fizz: Int = s.loadUint(7);
```

### Slice.preloadUint

```tact
extends fun preloadUint(self: Slice, l: Int): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads and returns an unsigned `l`-bit [`Int{:tact}`][int] from the [`Slice{:tact}`][slice], for $0 ≤ l ≤ 256$. Doesn't modify the [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeUint(42, 7).asSlice();
let fizz: Int = s.preloadUint(7);
```

### Slice.loadInt

```tact
extends mutates fun loadInt(self: Slice, l: Int): Int;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads and returns a signed `l`-bit [`Int{:tact}`][int] from the [`Slice{:tact}`][slice], for $0 ≤ l ≤ 257$.

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let fizz: Int = s.loadInt(7);
```

### Slice.preloadInt

```tact
extends fun preloadInt(self: Slice, l: Int): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads and returns a signed `l`-bit [`Int{:tact}`][int] from the [`Slice{:tact}`][slice], for $0 ≤ l ≤ 257$. Doesn't modify the [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let fizz: Int = s.preloadInt(7);
```

### Slice.loadBits

```tact
extends mutates fun loadBits(self: Slice, l: Int): Slice;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads $0 ≤$ `l` $≤ 1023$ bits from the [`Slice{:tact}`][slice] and returns them as a separate [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let fizz: Slice = s.loadBits(7);
```

### Slice.preloadBits

```tact
extends fun preloadBits(self: Slice, l: Int): Slice;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads $0 ≤$ `l` $≤ 1023$ bits from the [`Slice{:tact}`][slice] and returns them as a separate [`Slice{:tact}`][slice]. Doesn't modify the original [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let fizz: Slice = s.preloadBits(7);
```

:::note

  In order to reduce gas usage, prefer using this function over calling [`Slice.firstBits(){:tact}`](#slicefirstbits), since the latter is less optimized.

:::

### Slice.skipBits

```tact
extends mutates fun skipBits(self: Slice, l: Int);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads all but the first $0 ≤$ `l` $≤ 1023$ bits from the [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `l` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
s.skipBits(5);                   // all but first 5 bits
let fizz: Slice = s.loadBits(1); // load only 1 bit
```

### Slice.skipLastBits

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun skipLastBits(self: Slice, len: Int);
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads all but the last $0 ≤$ `len` $≤ 1023$ bits from the [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `len` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let allButLastFive: Slice = s.skipLastBits(5); // all but last 5 bits,
                                               // i.e. only the first 2
```

### Slice.loadBool

```tact
extends mutates fun loadBool(self: Slice): Bool;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads a single bit and returns a [`Bool{:tact}`][bool] value from the [`Slice{:tact}`][slice]. Reads `true{:tact}` if the loaded bit is equal to $1$, and reads `false{:tact}` otherwise.

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeBool(true).asSlice();
let fizz: Bool = s.loadBool(); // true
```

### Slice.skipBool

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipBool(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Skips a single bit from the [`Slice{:tact}`][slice]. Similar to discarding the return value of `Slice.loadBool()`.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell()
    .storeBool(true)
    .storeUint(42, 7)
    .asSlice();

s.skipBool();
let fizz: Int = s.loadUint(7); // 42
```

### Slice.loadBit

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
extends mutates fun loadBit(self: Slice): Bool;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

An alias to [`Slice.loadBool(){:tact}`](#sliceloadbool).

Usage example:

```tact
let s: Slice = beginCell().storeBit(true).asSlice();
let fizz: Bool = s.loadBit(); // true
```

### Slice.loadCoins

```tact
extends mutates fun loadCoins(self: Slice): Int;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads and returns a [serialized](#builderstorecoins) unsigned [`Int{:tact}`][int] value in the range from $0$ to $2^{120} - 1$ inclusive from the [`Slice{:tact}`][slice]. This value usually represents the amount in [nanoToncoins](/book/integers#nanotoncoin).

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeCoins(42).asSlice();
let fizz: Int = s.loadCoins(); // 42
```

:::note[Useful links:]

  [Special `coins{:tact}` serialization type](/book/integers#serialization-varint)

:::

### Slice.skipCoins

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipCoins(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Skips a serialized unsigned [`Int{:tact}`][int] value in the range from $0$ to $2^{120} - 1$ inclusive from the [`Slice{:tact}`][slice]. Similar to discarding the return value of `Slice.loadCoins()`.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell()
    .storeCoins(239)
    .storeUint(42, 7)
    .asSlice();

s.skipCoins();
let fizz: Int = s.loadUint(7); // 42
```

### Slice.loadVarUint16

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends mutates fun loadVarUint16(self: Slice): Int;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

An alias to [`Slice.loadCoins(){:tact}`](#sliceloadcoins).

Usage example:

```tact
let s: Slice = beginCell().storeVarUint16(42).asSlice();
let fizz: Int = s.loadVarUint16(); // 42
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Slice.skipVarUint16

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipVarUint16(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Alias to `Slice.skipCoins()`.

Usage example:

```tact
let s: Slice = beginCell()
    .storeVarUint16(239)
    .storeUint(42, 7)
    .asSlice();

s.skipVarUint16();
let fizz: Int = s.loadUint(7); // 42
```

### Slice.loadVarInt16

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends mutates fun loadVarInt16(self: Slice): Int;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Similar to [`Slice.loadCoins(){:tact}`](#sliceloadcoins), but with a different `value` range: from $-2^{119}$ to $2^{119} - 1$ inclusive.

Attempts to load more data than [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeVarInt16(-42).asSlice();
let fizz: Int = s.loadVarInt16(); // -42
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Slice.skipVarInt16

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipVarInt16(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Similar to `Slice.skipCoins()`, but with a different `value` range: from $-2^{119}$ to $2^{119} - 1$ inclusive.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell()
    .storeVarInt16(-239)
    .storeUint(42, 7)
    .asSlice();

s.skipVarInt16();
let fizz: Int = s.loadUint(7); // 42
```

### Slice.loadVarUint32

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends mutates fun loadVarUint32(self: Slice): Int;
```

Loads and returns a [serialized](#builderstorevaruint32) unsigned [`Int{:tact}`][int] value in the range from $0$ to $2^{248} - 1$ inclusive from the [`Slice{:tact}`][slice].

Attempts to load more data than [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeVarUint32(420000).asSlice();
let fizz: Int = s.loadVarUint32(); // 420000
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Slice.skipVarUint32

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipVarUint32(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Skips a serialized unsigned [`Int{:tact}`][int] value in the range from $0$ to $2^{248} - 1$ inclusive from the [`Slice{:tact}`][slice]. Similar to discarding the return value of `Slice.loadVarUint32()`.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell()
    .storeVarUint32(239)
    .storeUint(42, 7)
    .asSlice();

s.skipVarUint32();
let fizz: Int = s.loadUint(7); // 42
```

### Slice.loadVarInt32

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends mutates fun loadVarInt32(self: Slice): Int;
```

Similar to [`Slice.loadVarUint32(){:tact}`](#sliceloadvaruint32), but with a different `value` range: from $-2^{247}$ to $2^{247} - 1$ inclusive.

Attempts to load more data than [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeVarInt32(-420000).asSlice();
let fizz: Int = s.loadVarInt32(); // -420000
```

:::note[Useful links:]

  [Types of variable bit-width](/book/integers#serialization-varint)

:::

### Slice.skipVarInt32

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipVarInt32(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Similar to `Slice.skipVarUint32()`, but with a different `value` range: from $-2^{247}$ to $2^{247} - 1$ inclusive.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell()
    .storeVarInt32(-239)
    .storeUint(42, 7)
    .asSlice();

s.skipVarInt32();
let fizz: Int = s.loadUint(7); // 42
```

### Slice.loadAddress

```tact
extends mutates fun loadAddress(self: Slice): Address;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads and returns an [`Address{:tact}`][p] from the [`Slice{:tact}`][slice].

Attempts to load more data than [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeAddress(myAddress()).asSlice();
let fizz: Address = s.loadAddress();
```

### Slice.skipAddress

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipAddress(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Skips an [`Address{:tact}`][p] from the [`Slice{:tact}`][slice].

Attempts to skip more data than [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s1: Slice = beginCell()
    .storeAddress(myAddress())
    .storeUint(42, 32)
    .asSlice();

s1.skipAddress();
let fizz: Int = s1.loadUint(32); // 42
```

### Slice.loadRef

```tact
extends mutates fun loadRef(self: Slice): Cell;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads the next reference from the [`Slice{:tact}`][slice] as a [`Cell{:tact}`][cell].

Attempts to load more data than [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
let s1: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Cell = s1.loadRef();

let s2: Slice = beginCell()
    .storeRef(emptyCell())
    .storeRef(s1.asCell())
    .asSlice();
let ref1: Cell = s2.loadRef();
let ref2: Cell = s2.loadRef();
ref1 == ref2; // false
```

### Slice.preloadRef

```tact
extends fun preloadRef(self: Slice): Cell;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads the next reference from the [`Slice{:tact}`][slice] as a [`Cell{:tact}`][cell]. Doesn't modify the original [`Slice{:tact}`][slice].

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
let s1: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Cell = s1.preloadRef(); // doesn't modify s1

let s2: Slice = beginCell()
    .storeRef(emptyCell())
    .storeRef(s1.asCell())
    .asSlice();

let ref1: Cell = s2.preloadRef();
let ref2: Cell = s2.preloadRef();
ref1 == ref2; // true
```

### Slice.skipRef

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipRef(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Skips the next reference from the [`Slice{:tact}`][slice]. Similar to discarding the return value of `Slice.loadRef()`.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s1: Slice = beginCell()
    .storeRef(emptyCell())
    .storeUint(42, 32)
    .asSlice();

s1.skipRef();
let fizz: Int = s1.loadUint(32); // 42
```


### Slice.loadMaybeRef

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends mutates fun loadMaybeRef(self: Slice): Cell?;
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Loads a single bit from the [`Slice{:tact}`][slice]: if it's $1$, the referenced [`Cell{:tact}`][cell] is loaded and returned. If the loaded bit is $0$, nothing else is loaded and `null{:tact}` is returned.

Attempts to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s = msg.asSlice();
let outActions = s.loadMaybeRef();

if (outActions != null) {
    let actions = outActions!!;
    // process actions
}
```

### Slice.preloadMaybeRef

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun preloadMaybeRef(self: Slice): Cell?;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads a single bit from the [`Slice{:tact}`][slice]: if it's $1$, the referenced [`Cell{:tact}`][cell] is preloaded and returned. If the preloaded bit is $0$, `null{:tact}` is returned. Doesn't modify the original [`Slice{:tact}`][slice].

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
let s1: Slice = beginCell().storeMaybeRef(emptyCell()).asSlice();
let fizz: Cell = s1.preloadMaybeRef(); // returns emptyCell() and doesn't modify s1

let s2: Slice = beginCell()
    .storeMaybeRef(null)
    .storeMaybeRef(s1.asCell())
    .asSlice();

let ref1: Cell = s2.preloadMaybeRef(); // returns null and doesn't modify s2
let ref2: Cell = s2.preloadMaybeRef(); // same effect
ref1 == null; // true
ref1 == ref2; // true
```

### Slice.skipMaybeRef

<Badge text="Available since Tact 1.6.2" variant="tip" size="medium"/><p/>

```tact
extends mutates fun skipMaybeRef(self: Slice);
```

Extension mutation function for the [`Slice{:tact}`][slice] type.

Skips `Cell?` from the [`Slice{:tact}`][slice]. Similar to discarding the return value of `Slice.loadMaybeRef()`.

Attempts to skip more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s1: Slice = beginCell()
    .storeMaybeRef(emptyCell())
    .storeUint(42, 32)
    .asSlice();

s1.skipMaybeRef();
let fizz: Int = s1.loadUint(32); // 42
```

### Slice.refs

```tact
extends fun refs(self: Slice): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Returns the number of references in the [`Slice{:tact}`][slice] as an [`Int{:tact}`][int].

Usage example:

```tact
let s: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Int = s.refs();
```

### Slice.bits

```tact
extends fun bits(self: Slice): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Returns the number of data bits in the [`Slice{:tact}`][slice] as an [`Int{:tact}`][int].

Usage example:

```tact
let s: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Int = s.bits();
```

### Slice.firstBits

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun firstBits(self: Slice, len: Int): Slice;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads the first $0 ≤$ `len` $≤ 1023$ bits from the [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `len` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let firstFive: Slice = s.firstBits(5); // first 5 bits
```

:::note

  In order to reduce gas usage, prefer calling [`Slice.preloadBits(){:tact}`](#slicepreloadbits) over using this function, since the former is more optimized.

:::

### Slice.lastBits

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun lastBits(self: Slice, len: Int): Slice;
```

Extension function for the [`Slice{:tact}`][slice] type.

Preloads the last $0 ≤$ `len` $≤ 1023$ bits from the [`Slice{:tact}`][slice].

Attempts to specify an out-of-bounds `len` value throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Attempts to preload more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let lastFive: Slice = s.lastBits(5); // last 5 bits
```

### Slice.depth

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun depth(self: Slice): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Computes and returns the [`Int{:tact}`][int] [depth][std-repr] of the [`Slice{:tact}`][slice]. Produces $0$ if the [`Slice{:tact}`][slice] has no references. Otherwise, it returns $1$ plus the maximum of the depths of the referenced cells.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).asSlice();
let depth: Int = s.depth(); // 0
```

### Slice.computeDataSize

<Badge text="500+ gas" title="Uses 500 gas units or more" variant="danger" size="medium"/>
<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun computeDataSize(self: Slice, maxCells: Int): DataSize;
```

Extension function for the [`Slice{:tact}`][slice] type.

Similar to [`Cell.computeDataSize(){:tact}`](#cellcomputedatasize), but does not take into account the cell that contains the [`Slice{:tact}`][slice] itself. However, it accounts for its bits and refs.

The results are packed into a `DataSize{:tact}` [struct][struct] consisting of:

Field   | Type                | Description
:------ | :------------------ | :----------
`cells` | [`Int{:tact}`][int] | The total number of nested cells, including the starting one
`bits`  | [`Int{:tact}`][int] | The total number of bits in all nested cells, including the starting one
`refs`  | [`Int{:tact}`][int] | The total number of refs in all nested cells, including the starting one

If the specified `maxCells` value is insufficient to traverse all cells **not** including the starting one, an exception with [exit code 8](/book/exit-codes#8) is thrown: `Cell overflow`.

Attempts to specify a negative value for `maxCells` throw an exception with [exit code 5](/book/exit-codes#5): `Integer out of expected range`.

Usage example:

```tact
let s: Slice = beginCell().storeInt(42, 7).storeRef(emptyCell()).asSlice();
try {
    let dataSize: DataSize = s.computeDataSize(1);
    dataSize.cells; // 1
    dataSize.bits;  // 7
    dataSize.refs;  // 1
} catch (exitCode) {
    // if maxCells was insufficient to traverse the cell
    // and all of its references, the exitCode here would be 8
}
```

### Slice.empty

```tact
extends fun empty(self: Slice): Bool;
```

Extension function for the [`Slice{:tact}`][slice] type.

Checks whether the [`Slice{:tact}`][slice] is empty (i.e., contains no bits of data and no cell references). Returns `true{:tact}` if it is empty, `false{:tact}` otherwise.

Usage example:

```tact
let s: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Bool = s.empty();                     // false
let buzz: Bool = beginCell().asSlice().empty(); // true
```

:::note

  Unlike [`Slice.endParse(){:tact}`](#sliceendparse), this function does not throw any exceptions, even when the [`Slice{:tact}`][slice] is empty.

:::

### Slice.dataEmpty

```tact
extends fun dataEmpty(slice: Slice): Bool;
```

Extension function for the [`Slice{:tact}`][slice] type.

Checks whether the [`Slice{:tact}`][slice] has no bits of data. Returns `true{:tact}` if it has no data, `false{:tact}` otherwise.

Usage example:

```tact
let s: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Bool = s.dataEmpty();  // true

let s2: Slice = beginCell().storeInt(42, 7).asSlice();
let buzz: Bool = s2.dataEmpty(); // false
```

### Slice.refsEmpty

```tact
extends fun refsEmpty(slice: Slice): Bool;
```

Extension function for the [`Slice{:tact}`][slice] type.

Checks whether the [`Slice{:tact}`][slice] has no references. Returns `true{:tact}` if it has no references, `false{:tact}` otherwise.

Usage example:

```tact
let s: Slice = beginCell().storeRef(emptyCell()).asSlice();
let fizz: Bool = s.refsEmpty();                     // false
let buzz: Bool = beginCell().asSlice().refsEmpty(); // true
```

### Slice.endParse

```tact
extends fun endParse(self: Slice);
```

Extension function for the [`Slice{:tact}`][slice] type.

Checks whether the [`Slice{:tact}`][slice] is empty (i.e., contains no bits of data and no cell references). If it is not, it throws an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact {2,6}
let emptyOne: Slice = emptySlice();
emptyOne.endParse(); // nothing, as it's empty

let paul: Slice = "Fear is the mind-killer".asSlice();
try {
    paul.endParse(); // throws exit code 9
}
```

### Slice.hash

<Badge text="500+ gas" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>

```tact
extends fun hash(self: Slice): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Calculates and returns an [`Int{:tact}`][int] value of the [SHA-256][sha-2] hash of the [standard `Cell{:tact}` representation][std-repr] of the given [`Slice{:tact}`][slice].

Usage example:

```tact
let s: Slice = beginCell().asSlice();
let fizz: Int = s.hash();
```

### Slice.hashData

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun hashData(self: Slice): Int;
```

Extension function for the [`Slice{:tact}`][slice] type.

Calculates and returns an [`Int{:tact}`][int] value of the [SHA-256][sha-2] hash of the data bits from the given [`Slice{:tact}`][slice], which should have a number of bits divisible by 8.

Unlike [`sha256(){:tact}`](/ref/core-crypto#sha256), this function is gas-efficient and **only** hashes the data of the given [`Slice{:tact}`][slice], i.e. up to 1023 bits, ignoring the refs.

Attempts to specify a [`Slice{:tact}`][slice] with a number of bits **not** divisible by 8 throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
// Base64-encoded BoC with "Hello, World!"
let short: Slice = slice("te6cckEBAQEADgAAGEhlbGxvIHdvcmxkIXgtxbw=");

// It's enough to only take the hash of the data
sha256(short) == short.hashData(); // true

// But if we construct a slice larger than 1023 bits with all refs combined,
// we must use sha256() or we'll get skewed results or even collisions

let tmp: Builder = beginCell();
repeat (127) { tmp = tmp.storeUint(69, 8) } // storing 127 bytes
let ref: Cell = beginCell().storeUint(33, 8).endCell();
let long: Slice = tmp.storeRef(ref).asSlice(); // plus a ref with a single byte

// Hashing just the data bits in the current slice isn't enough
sha256(long) == long.hashData(); // false!
```

### Slice.asCell

<Badge text="500+ gas" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>

```tact
extends fun asCell(self: Slice): Cell;
```

Extension function for the [`Slice{:tact}`][slice] type.

Converts the [`Slice{:tact}`][slice] to a [`Cell{:tact}`][cell] and returns it. An alias to `beginCell().storeSlice(self).endCell(){:tact}`.

Usage example:

```tact
let s: Slice = beginCell().asSlice();
let fizz: Cell = s.asCell();
let buzz: Cell = beginCell().storeSlice(s).endCell();

fizz == buzz; // true
```

### Slice.asString

```tact
extends fun asString(self: Slice): String;
```

Extension function for the [`Slice{:tact}`][slice] type.

Casts the [`Slice{:tact}`][slice] to a [`String{:tact}`][p] and returns it. The inverse of [`String.asSlice(){:tact}`](/ref/core-strings#stringasslice).

Usage example:

```tact
let s: String = "Keep your Slices close, but your Strings closer.";
let fizz: String = s;
let buzz: String = s.asSlice().asString();

fizz == buzz; // true
```

### Slice.fromBase64

<Badge text="500+ gas" title="Uses 500 gas units or more" variant="danger" size="medium"/><p/>

```tact
extends fun fromBase64(self: Slice): Slice;
```

Extension function for the [`Slice{:tact}`][slice] type.

Returns a new [`Slice{:tact}`][slice] from the decoded [Base64](https://en.wikipedia.org/wiki/Base64) [`Slice{:tact}`][slice].

Note that this function is limited and only takes the first 1023 bits of data from the given [`Slice{:tact}`][slice], without throwing an exception if the [`Slice{:tact}`][slice] has more data (i.e., when it has any references).

If the given [`Slice{:tact}`][slice] contains characters not from the Base64 set, an exception with [exit code 134](/book/exit-codes#134) will be thrown: `Invalid argument`.

Usage example:

```tact
let s: Slice = "SSBhbSBHcm9vdC4=".asSlice();
let fizz: Slice = s.fromBase64();
```

### Slice.asAddress

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun asAddress(self: Slice, chain: Int): Address;
```

Extension function for the [`Slice{:tact}`][slice] type.

Casts the [`Slice{:tact}`][slice] to an [`Address{:tact}`][p] on a given `chain` ID and returns it. It is the inverse of [`Address.asSlice(){:tact}`](/ref/core-addresses#addressasslice) and a safe but more gas-expensive version of [`Slice.asAddressUnsafe(){:tact}`](#sliceasaddressunsafe).

Attempts to specify a [`Slice{:tact}`][slice] with an invalid [account ID](https://docs.ton.org/learn/overviews/addresses#account-id) length throw an error with [exit code 136](/book/exit-codes#): `Invalid standard address`.

Attempts to specify a [`Slice{:tact}`][slice] with an invalid tag prefix (not `0b100`) or with an invalid [account ID](https://docs.ton.org/learn/overviews/addresses#account-id) length (not 256 bits) throw an error with [exit code 136](/book/exit-codes#): `Invalid standard address`.

Usage example:

```tact
let a: Address = myAddress(); // let's assume we're in a basechain
let a2: Address = a.asSlice().asAddress(0); // so the chain ID is 0

a == a2; // true
```

:::note

  Because of the checks performed, this function is more gas-expensive than its unsafe but cheaper counterpart: [`Slice.asAddressUnsafe(){:tact}`](#sliceasaddressunsafe).

:::

### Slice.asAddressUnsafe

<Badge text="Available since Tact 1.6" variant="tip" size="medium"/><p/>

```tact
extends fun asAddressUnsafe(self: Slice): Address;
```

Extension function for the [`Slice{:tact}`][slice] type.

Unsafely casts the [`Slice{:tact}`][slice] to an [`Address{:tact}`][p] and returns it. The inverse of [`Address.asSlice(){:tact}`](/ref/core-addresses#addressasslice).

This function does **not** perform any checks on the contents of the [`Slice{:tact}`][slice].

Usage example:

```tact
let a: Address = myAddress();
let a2: Address = a.asSlice().asAddressUnsafe();

a == a2; // true
```

:::caution

  Use it only if you want to optimize the code for gas and can guarantee in advance that the [`Slice{:tact}`][slice] contains the data of an [`Address{:tact}`][p].

  Otherwise, use the safer but more gas-expensive [`Slice.asAddress(){:tact}`](#sliceasaddress) function.

:::

## Struct.toCell

```tact
extends fun toCell(self: Struct): Cell;
```

Extension function for any [struct][struct] type.

Converts the struct to a [`Cell{:tact}`][cell] and returns it.

Usage example:

```tact
struct GuessCoin {
    probably: Int as coins;
    nothing: Int as coins;
}

fun coinCell(): Cell {
    let s: GuessCoin = GuessCoin { probably: 42, nothing: 27 };
    let fizz: Cell = s.toCell();

    return fizz; // "x{12A11B}"
}
```

## Struct.toSlice

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
extends fun toSlice(self: Struct): Slice;
```

Extension function for any [struct][struct] type.

Converts the struct to a [`Slice{:tact}`][slice] and returns it. An alias to `self.toCell().asSlice(){:tact}`.

Usage example:

```tact
struct GuessCoin {
    probably: Int as coins;
    nothing: Int as coins;
}

fun coinSlice(): Slice {
    let s: GuessCoin = GuessCoin { probably: 42, nothing: 27 };
    let fizz: Slice = s.toSlice();

    return fizz; // "CS{Cell{000612a11b} bits: 0..24; refs: 0..0}"
}
```

## Struct.fromCell

```tact
fun Struct.fromCell(cell: Cell): Struct;
```

Extension function for any [struct][struct] type.

Converts a [`Cell{:tact}`][cell] into the specified struct and returns that struct.

Attempts to pass a [`Cell{:tact}`][cell] with a layout different from the specified struct or to load more data than the [`Cell{:tact}`][cell] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
struct GuessCoin {
    probably: Int as coins;
    nothing: Int as coins;
}

fun directParse(payload: Cell): GuessCoin {
    return GuessCoin.fromCell(payload);
}

fun cautiousParse(payload: Cell): GuessCoin? {
    let coin: GuessCoin? = null;
    try {
        coin = GuessCoin.fromCell(payload);
    } catch (e) {
        dump("Cell payload doesn't match GuessCoin struct!");
    }
    return coin;
}
```

## Struct.fromSlice

```tact
fun Struct.fromSlice(slice: Slice): Struct;
```

Extension function for any [Struct][struct] type.

Converts a [`Slice{:tact}`][slice] into the specified struct and returns that struct.

Attempts to pass a [`Slice{:tact}`][slice] with a layout different from the specified struct or to load more data than the [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
struct GuessCoin {
    probably: Int as coins;
    nothing: Int as coins;
}

fun directParse(payload: Slice): GuessCoin {
    return GuessCoin.fromSlice(payload);
}

fun cautiousParse(payload: Slice): GuessCoin? {
    let coin: GuessCoin? = null;
    try {
        coin = GuessCoin.fromSlice(payload);
    } catch (e) {
        dump("Slice payload doesn't match GuessCoin struct!");
    }
    return coin;
}
```

## Message.toCell

```tact
extends fun toCell(self: Message): Cell;
```

Extension function for any [Message][message] type.

Converts the [Message][message] to a [`Cell{:tact}`][cell] and returns it.

Usage example:

```tact
message GuessCoin {
    probably: Int as coins;
    nothing: Int as coins;
}

fun coinCell(): Cell {
    let s: GuessCoin = GuessCoin { probably: 42, nothing: 27 };
    let fizz: Cell = s.toCell();

    return fizz; // "x{AB37107712A11B}"
}
```

## Message.toSlice

<Badge text="Available since Tact 1.5" variant="tip" size="medium"/><p/>

```tact
extends fun toSlice(self: Message): Slice;
```

Extension function for any [Message][message] type.

Converts the [Message][message] to a [`Slice{:tact}`][slice] and returns it. An alias to `self.toCell().asSlice(){:tact}`.

Usage example:

```tact
message GuessCoin {
    probably: Int as coins;
    nothing: Int as coins;
}

fun coinSlice(): Slice {
    let s: GuessCoin = GuessCoin { probably: 42, nothing: 27 };
    let fizz: Slice = s.toSlice();

    return fizz; // "CS{Cell{000eab37107712a11b} bits: 0..56; refs: 0..0}"
}
```

## Message.fromCell

```tact
fun Message.fromCell(cell: Cell): Message;
```

Extension function for any [Message][message] type.

Converts a [`Cell{:tact}`][cell] into the specified [Message][message] and returns that [Message][message].

Attempts to pass a [`Cell{:tact}`][cell] that contains an [opcode prefix][opcode] of a different message throw an exception with [exit code 129](/book/exit-codes#129): `Invalid serialization prefix`.

Attempts to pass a [`Cell{:tact}`][cell] with a layout different from the specified [Message][message] or to load more data than a [`Cell{:tact}`][cell] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
message(0x777) TripleAxe {
    prize: Int as uint32;
}

fun directParse(payload: Cell): TripleAxe {
    return TripleAxe.fromCell(payload);
}

fun cautiousParse(payload: Cell): TripleAxe? {
    let coin: TripleAxe? = null;
    try {
        coin = TripleAxe.fromCell(payload);
    } catch (e) {
        dump("Cell payload doesn't match TripleAxe Message!");
    }
    return coin;
}
```

## Message.fromSlice

```tact
fun Message.fromSlice(slice: Slice): Message;
```

Extension function for any [Message][message] type.

Converts a [`Slice{:tact}`][slice] into the specified [Message][message] and returns that [Message][message].

Attempts to pass a [`Slice{:tact}`][slice] that contains an [opcode prefix][opcode] of a different message throw an exception with [exit code 129](/book/exit-codes#129): `Invalid serialization prefix`.

Attempts to pass a [`Slice{:tact}`][slice] with a layout different from the specified [Message][message] or to load more data than a [`Slice{:tact}`][slice] contains throw an exception with [exit code 9](/book/exit-codes#9): `Cell underflow`.

Usage examples:

```tact
message(0x777) TripleAxe {
    prize: Int as uint32;
}

fun directParse(payload: Slice): TripleAxe {
    return TripleAxe.fromSlice(payload);
}

fun cautiousParse(payload: Slice): TripleAxe? {
    let coin: TripleAxe? = null;
    try {
        coin = TripleAxe.fromSlice(payload);
    } catch (e) {
        dump("Slice payload doesn't match TripleAxe Message!");
    }
    return coin;
}
```

## Message.opcode

<Badge text="Available since Tact 1.6.7" variant="tip" size="medium"/><p/>

```tact
fun Message.opcode(): Int;
```

Extension function for any [Message][message] type.

Returns the [opcode][opcode] of the [Message][message].

Usage example:

```tact
message(0x777) TripleAxe {
    prize: Int as uint32;
}

contract Example {
    receive(msg: TripleAxe) {
        dump(TripleAxe.opcode()); // 0x777
   }
}
```

## Contract.toCell

<Badge text="Available since Tact 1.6.12" variant="tip" size="medium"/><p/>

```tact
extends fun toCell(self: Contract): Cell;
```

Extension function for any [contract][contract] type.

Converts the contract state to a [`Cell{:tact}`][cell] and returns it.

Usage example:

```tact
contract Example {
    probably: Int as coins = 42;
    nothing: Int as coins = 27;

    get fun asCell(): Cell {
        return self.toCell();
    }
}
```

:::note

    If a contract doesn't use [contract parameters](/book/contracts#parameters), the resulting `Cell{:tact}` or `Slice{:tact}` will contain a leading one bit representing the [lazy initialization bit](/book/functions/#init).

:::

## Contract.toSlice

<Badge text="Available since Tact 1.6.12" variant="tip" size="medium"/><p/>

```tact
extends fun toSlice(self: Contract): Slice;
```

Extension function for any [contract][contract] type.

Converts the contract state to a [`Slice{:tact}`][slice] and returns it. An alias to `self.toCell().asSlice(){:tact}`.

Usage example:

```tact
contract Example {
    probably: Int as coins = 42;
    nothing: Int as coins = 27;

    get fun asSlice(): Slice {
        return self.toSlice();
    }
}
```

:::note

    If a contract doesn't use [contract parameters](/book/contracts#parameters), the resulting `Cell{:tact}` or `Slice{:tact}` will contain a leading one bit representing the [lazy initialization bit](/book/functions/#init).

:::

[p]: /book/types#primitive-types
[bool]: /book/types#booleans
[int]: /book/integers
[cell]: /book/cells#cells
[builder]: /book/cells#builders
[slice]: /book/cells#slices
[map]: /book/maps
[struct]: /book/structs-and-messages#structs
[contract]: /book/contracts
[message]: /book/structs-and-messages#messages
[opcode]: /book/structs-and-messages#message-opcodes
[null]: /book/optionals

[std-repr]: /book/cells#cells-representation

[tlb]: https://docs.ton.org/develop/data-formats/tl-b-language
[sha-2]: https://en.wikipedia.org/wiki/SHA-2#Hash_standard
[dfs]: https://en.wikipedia.org/wiki/Depth-first_search
[gas]: https://docs.ton.org/v3/documentation/smart-contracts/transaction-fees/fees#gas
