Skip to content

Rust Program SDK Overview

View as Markdown

Use the Rust program SDK when you want to write on-chain Thru programs in no_std Rust instead of C. It targets the same Thru VM and the same syscall surface as the C SDK, with safe wrappers around account access.

For Rust services, CLIs, and backends that talk to a node over gRPC, use the host-side crates in Rust SDKs Overview instead.

Install the CLI and development prerequisites through Set Up Thru DevKit, then install the toolchain and the Rust SDK:

Terminal window
thru dev toolchain install
thru dev sdk install rust

The CLI installs the Rust SDK under ~/.thru/sdk/rust. Programs compile with cargo for the RISC-V target riscv64imac-unknown-none-elf, so you also need a Rust toolchain with that target and cargo-binutils installed:

Terminal window
rustup target add riscv64imac-unknown-none-elf
cargo install cargo-binutils
rustup component add llvm-tools
Terminal window
test -f ~/.thru/sdk/rust/Cargo.toml
test -d ~/.thru/sdk/rust/core
test -d ~/.thru/sdk/rust/macros
rustup target list --installed | grep riscv64imac-unknown-none-elf
CrateWhat it provides
thru-coreAccount access (AccountManager, AccountRef), transaction and block context, syscall wrappers, VM pointer helpers, program utilities, and logging/revert macros.
thru-sdk-macrosThe #[entry] attribute macro that emits the VM boot shim and the exported start symbol.

Both crates are no_std. thru-core also re-exports heapless, which the tvm_println! macro uses for stack-allocated formatting.

#![no_std]
#![no_main]
use thru_core::syscall::sys_emit_event;
use thru_sdk_macros::*;
#[entry(stack_size = 4096)]
fn main(_instr_data: &[u8]) -> Result<u64, u64> {
let message = b"hello from a Rust Thru program\0";
unsafe { sys_emit_event(message.as_ptr(), message.len() as u64) };
Ok(0)
}
If you need…Open this page
The shape of a program, entry signatures, and how it exitsProgram Structure
How to read accounts, transaction fields, and block context safelyAccounts and Transaction Context
The raw syscall wrappers and their safe AccountManager equivalentsSyscalls
How to invoke another program and delegate authorityCross-Program Invocation
Return codes, reverts, and the error enumsError Handling and Return Codes
Cargo, linker, and make wiring for a downstream projectBuild Integration