---
# System prepended metadata

title: Originating a Smart Rollup

---

# Originating a Smart Rollup

Now that the [Kernel Gallery](https://www.marigold.dev/post/announcing-smart-rollups-kernel-gallery) has been introduced, it's time to build and originate one of the example.

This blog post will assume that you have access to the `octez-smart-rollup-client-PtMumbai` and the `octez-client` binaries, you can install them by following this [documentation](https://tezos.gitlab.io/introduction/howtoget.html#installing-binaries).

## Building the Kernel Gallery

The Kernel Gallery is a set of kernels written in Rust, so you will need to install [Rust](https://www.rust-lang.org/learn/get-started) on your computer:

```bash
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

Then you can clone the [Kernel Gallery](https://gitlab.com/tezos/kernel-gallery) on your computer.

```bash
$ git clone git@gitlab.com:tezos/kernel-gallery.git
```

You will notice a file `rust-toolchain` that forces the rust to use the version 1.66.0. To make sure you have the correct installed Rust version you can use this command:

```bash
$ rustup --version
> rustup 1.26.0 (5af9b9484 2023-04-05)
> info: This is the version for the rustup toolchain manager, not the rustc compiler.
> info: The currently active `rustc` version is `rustc 1.66.0 (69f9c33d7 2022-12-12)
```

The kernels are compile to Wasm, to compile some Rust code to Wasm you need to add the `wasm32-unknown-unknown` to the Rust compiler

```bash
$ rustup target add wasm32-unknown-unknown
> info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
> info: installing component 'rust-std' for 'wasm32-unknown-unknown'
```

To make sure everything is working you can compile all the kernel of the Kernel Gallery:

```bash
$ cargo build --target wasm32-unknown-unknown
> ...
> Finished dev [unoptimized + debuginfo] target(s) in 8.61s
```

> On Macos you may have some troubles when compiling the Kernel Gallery, so we added a section in the [readme](https://gitlab.com/tezos/kernel-gallery#additional-setup-for-mac) of the Kernel Gallery to help you solve the issue 


## Originate a small Smart Rollup

Let's try to originate the [debug kernel](https://gitlab.com/tezos/kernel-gallery/-/tree/main/00_debug_kernel) that only display "Hello from kernel!" on each new Tezos block level.

This kernel is simple to originate because when built, its size is smaller than 24KB.

First step: let's build it.

```bash
$ cd 00_debug_kernel
$ cargo build --release --target wasm32-unknown-unknown
> Finished release [optimized] target(s) in 0.16s
```

A wasm file should be present under `../target/wasm32-unknown-unknown/release/debug_kernel.wasm`

If you check the size of this kernel, you will notice that it is still too big to be originated directly on the layer 1.

```bash
$ cd ../
$ ls -lh target/wasm32-unknown-unknown/release/debug_kernel.wasm
```

To reduce the size of the kernel, you can use [wasm-strip](https://github.com/WebAssembly/wabt). Be careful, `wasm-strip` will replace the existing kernel.

```bash
$ wasm-strip target/wasm32-unknown-unknown/release/debug_kernel.wasm
```

Then you should see that the size has been reduced dramatically.

Let's convert your kernel to binary before originating it.

```bash
$ xxd -ps -c 0 target/wasm32-unknown-unknown/release/debug_kernel.wasm | tr -d '\n' > kernel.hex
```

A `kernel.hex` should be present on your computer then.

Next, we can originate the kernel! To do so, you need an account with enough tez to pay the fees (in our case it will be "bob") and you also need to configure the `octez-client` to use a test network like the Ghostnet.

```bash
$ octez-client --endpoint https://ghostnet.tezos.marigold.dev config update
$ octez-client originate smart rollup "my-rollup" \
  from "bob" \
  of kind wasm_2_0_0 \
  of type unit \
  with kernel "file:kernel.hex" \
  --burn-cap 999 \
  --force
> Estimated gas: 2748.229 units (will add 100 for safety)
> Estimated storage: 6552 bytes added (will add 20 for safety)
> Operation successfully injected in the node
> ...
> Smart rollup sr1xxxxxx memorized as "my-rollup"
```

> No need to remember the name of your rollup, we will use the alias "my-rollup" in the next step.

Finally, you can start your rollup. The `--data-dir` represents the data directory of your rollup.

```bash
$ octez-smart-rollup-node-PtNairob run operator \
    for "my-rollup" \
    with operators "bob" \
    --data-dir "rollup"
```

## Originate a bigger Smart Rollup

But it might happen that your kernel is bigger than 24KB even after using `wasm-strip`. Because a Tezos operation size is limited to 32Kb, you can't directly originate your kernel on the layer 1.

Let use the [debug kernel](https://gitlab.com/tezos/kernel-gallery/-/tree/main/00_debug_kernel) without using `wasm-strip` as a big kernel.

The compilation step has not changed

```bash
$ cd 00_debug_kernel
$ cargo build --release --target wasm32-unknown-unknown
$ cd ../
```

To originate this kernel, we will use the [data reveal channel](https://research-development.nomadic-labs.com/introducing-data-availability-committees.html#the-reveal-data-channel) of the rollup, the name of the data reveal channel folder is `wasm_2_0_0`, and it is located under the data directory of your rollup.

Because starting the DAC to only originate your kernel is not convenient, [TriliTech](https://www.trili.tech/) has developed a tool to help you originate a big kernel: [tezos-smart-rollup-installer](https://crates.io/crates/tezos-smart-rollup-installer).

It will split your kernel into chunks, provide you a kernel that will install yours by using the data reveal channel.

First, let's install the tool:

```bash
$ cargo install tezos-smart-rollup-installer
```

Then you can generate the installer and the rollup data directory:

```bash
$ smart-rollup-installer get-reveal-installer \
    --upgrade-to target/wasm32-unknown-unknown/release/debug_kernel.wasm \
    --output kernel.hex \
    --preimages-dir rollup/wasm_2_0_0
```

A folder `rollup` should be present on your machine. This folder is the data directory of your rollup, the folder that interest us the most is the subfolder `wasm_2_0_0`, it's the data reveal directory, it contains your kernel splitted into different chunks of 4Kb. 

The command should have also created a `kernel.hex`. This kernel will install your kernel by reading the data reveal channel.

Next, you can originate the kernel installer:

```bash
$ octez-client originate smart rollup "my-rollup" \
  from "bob" \
  of kind wasm_2_0_0 \
  of type unit \
  with kernel "file:kernel.hex" \
  --burn-cap 999 \
  --force
```

Finally, you can start your rollup. Be careful, the `--data-dir` should point to the folder generated previously by the `get-reveal-installer` command.

```bash
$ octez-smart-rollup-node-PtNairob run operator \
    for "my-rollup" \
    with operators "bob" \
    --data-dir "rollup"
```

And voilà, your kernel is installed and running. Keep in mind that originating bigger kernel also works for small ones.
