Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quickstart: your first program on LEZ

From an empty shell to a program you wrote changing an account, all on a local sequencer with nothing on a public network. Expect about half an hour, most of it spent building.

A program is Rust: it compiles to a RISC Zero guest, its entry point is the actor_entrypoint! macro and its types come from the lee_core crate. Clients, wallets and services in any language talk to LEZ over JSON-RPC or the C ABI and never compile a guest.

What you need

A clone of the repository (Before you start), Rust (the workspace pins a toolchain in rust-toolchain.toml), the RISC Zero toolchain at the version the workspace uses (rzup install, then rzup install r0vm 3.1.0 and rzup install cargo-risczero 3.1.0; the wallet runs r0vm to prove private transactions and refuses one whose major and minor version differ from its risc0-zkvm crate), Docker for reproducible guest builds, and the system packages the repository’s README.md lists: on Debian or Ubuntu build-essential clang libclang-dev libssl-dev pkg-config, on macOS pkg-config openssl.

Install the wallet from the repository root:

cargo install --path lez/wallet --force --locked

--locked builds against the repository’s Cargo.lock.

Start a node

The quickest node for writing programs is the sequencer alone, without L1 or indexer:

just run-sequencer-standalone

It produces a block every 15 seconds. Running a node has the full stack, with an L1 node and the indexer, and what standalone leaves out.

Point the wallet at it

wallet change-network local
wallet check-health

Run change-network first, or every command below goes to the public testnet rather than your node. On first run the wallet asks for a password twice; an empty one is fine for a local devnet. Setting up the wallet has the networks and the password rules.

You should see ✅All looks good!.

Build the example programs

RISC0_DOCKER_CONTAINER_TAG=r0.1.91.1 \
CARGO_TARGET_DIR=target/examples/program_deployment/methods \
  cargo risczero build --manifest-path examples/program_deployment/methods/guest/Cargo.toml

export EXAMPLES=$(pwd)/target/examples/program_deployment/methods/riscv32im-risc0-zkvm-elf/docker

Both variables matter: the tag pins the builder image, which decides the image id, and the target directory makes the EXAMPLES path correct (Building).

Each program lands at $EXAMPLES/<name>.bin. Run the rest from examples/program_deployment.

What you are about to deploy

hello_world.rs is the whole program, fourteen lines including the comment:

use lee_core::program::{ReceiveInput, Response};

// Hello-world example program.
//
// This program reads an arbitrary sequence of bytes as its message
// and appends those bytes to this program's own actor state on the receiving account.

lee_core::actor_entrypoint!(handle_message);

fn handle_message(input: &ReceiveInput, greeting: Vec<u8>) -> Response {
    let mut bytes = input.pre_state.to_vec();
    bytes.extend(greeting);
    Response::set_state(bytes)
}

Every program built with actor_entrypoint! has this shape, except a raw handler, which decodes the message itself. The macro expands to main, and the handler gets a &ReceiveInput and your message type, here Vec<u8>, decoded (Handlers and messages). input.pre_state is this program’s state on the receiving account and nothing else: not the balance, not another program’s state.

A Response is returned, not mutated. Response::set_state(bytes) replaces this actor’s state; keep_state() leaves it; both can carry messages to other actors. The handler can write nowhere else; that is the model’s central rule (The model in one page).

Its manifest needs only lee_core, borsh and risc0-zkvm (Toolchain shows them for a crate outside this repository).

Two accounts

You need an account for the program to write to, and a funded account to pay the fees.

wallet account new public --label first

The payer has to hold native tokens already, and a new account holds none. On a local devnet, import one of the genesis-funded secrets the wallet-import-test-accounts recipe in the Justfile uses:

wallet account import public --secret <one of the two secrets in that recipe>

Take them from the recipe: they change with the devnet’s genesis.

New accounts start uninitialized. Confirm it:

wallet account get --scope all --account-id Public/<first account id>

It prints Account is Uninitialized. The Public/ prefix tells the wallet which state to query.

Run it

cargo run --bin run_hello_world $EXAMPLES/hello_world.bin <first account id> <payer account id>

The runners take bare base58 ids, without the Public/ or Private/ prefix the wallet prints. The runner deploys the program and then sends it a message, so there is no separate deploy step. Each run deploys a new copy with its own program id, so a second run does not extend the first run’s state (deploy_program, examples/program_deployment/src/lib.rs). It returns once the sequencer has accepted the message, not once a block includes it, so wait for the next block (up to 15 seconds locally) before reading the account or running another command that pays from the same account. Run too soon and the read says Account is Uninitialized, or the next send is refused because the payer’s nonce is already pending. Watch the sequencer’s terminal to see the block land.

Then read the account back:

wallet account get --raw --scope all --account-id Public/<first account id>
{
  "actor_states": {
    "<hello_world program account id>": "486f6c61206d756e646f21"
  },
  "nonce": 0
}

actor_states maps each program account id to that program’s state here. The command prints a Label: line above the JSON when the account has one, so the output does not pipe straight into jq. Decode the value:

echo 486f6c61206d756e646f21 | xxd -r -p

It prints Hola mundo!.

Without --raw the wallet prints the native balance and the nonce, then each other program’s state as hex under a Record of program <id> line.

The same program, privately

wallet account new private --label first-private
wallet auth-transfer send --from Public/<payer account id> --to first-private --amount 1000000000
cargo run --bin run_hello_world_private $EXAMPLES/hello_world.bin <private account id> <payer account id>

The payer pays to deploy, but a private execution pays its fee from inside the proof, out of a private account, and the new one holds nothing: without the transfer the runner fails with Fee reserve of … fails (unless the wallet owns another private account that holds the fee, which then pays it). The public sender pays for the transfer, and one billion covers every private run in this guide’s examples.

This takes minutes rather than seconds (ten on a laptop is not unusual): your machine executes and proves the program instead of the sequencer executing it.

Reading it back needs a sync first, because the chain holds only a commitment and an encrypted note:

wallet account sync-private
wallet account get --raw --scope all --account-id Private/<private account id>

The wallet reads a private account from its own copy, which it updates when a sync finds a note for it or when a transaction the wallet CLI sent is included. So before the sync it shows the balance the auth-transfer send left, but no hello_world state: the runner sends through the wallet library and records nothing about the private account (Reading the chain). After it, the state reads the same Hola mundo! as the public run, and the nonce is a large number rather than 0: a private account’s nonce is a hash chain, not a counter.

What just happened

Accounts, actors and state explains what an actor is, and Handlers and messages what else a handler may return.

The same binary served both runs, because a program is not told whether its account is public or private. The privacy model rests on that property; its limits are in What a private transaction reveals.

Deploying without a runner

The runners call deploy_program (examples/program_deployment/src/lib.rs), which creates the header and segment accounts, chunks the ELF, and marks the program immutable. To do it yourself, create the accounts, then use the loader:

wallet account new public --label my-header
wallet account new public --label my-seg-0   # and seg-1, seg-2, ...
wallet program-loader deploy \
  --elf $EXAMPLES/hello_world.bin \
  --header my-header \
  --segments my-seg-0 my-seg-1 my-seg-2 \
  --immutable \
  --payer Public/<payer account id>

Program code is stored in accounts: a header and segments (Deployment). Create one segment account per 96 KiB of the guest ELF inside the .bin (the wallet splits only that part, not the kernel the .bin also carries), and name a funded --payer; Deploying has the rules and the errors.

Next

The example programs walks the rest of the repository’s examples, each adding one idea: authorization, a message enum, sending to another actor, program-derived accounts, and gating on time.