Rust Program SDK Overview
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
Section titled “Install”Install the CLI and development prerequisites through Set Up Thru DevKit, then install the toolchain and the Rust SDK:
thru dev toolchain installthru dev sdk install rustThe 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:
rustup target add riscv64imac-unknown-none-elfcargo install cargo-binutilsrustup component add llvm-toolsVerify your install
Section titled “Verify your install”test -f ~/.thru/sdk/rust/Cargo.tomltest -d ~/.thru/sdk/rust/coretest -d ~/.thru/sdk/rust/macrosrustup target list --installed | grep riscv64imac-unknown-none-elfCrates
Section titled “Crates”| Crate | What it provides |
|---|---|
thru-core | Account access (AccountManager, AccountRef), transaction and block context, syscall wrappers, VM pointer helpers, program utilities, and logging/revert macros. |
thru-sdk-macros | The #[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.
Minimal program
Section titled “Minimal program”#![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)}Start here
Section titled “Start here”| If you need… | Open this page |
|---|---|
| The shape of a program, entry signatures, and how it exits | Program Structure |
| How to read accounts, transaction fields, and block context safely | Accounts and Transaction Context |
The raw syscall wrappers and their safe AccountManager equivalents | Syscalls |
| How to invoke another program and delegate authority | Cross-Program Invocation |
| Return codes, reverts, and the error enums | Error Handling and Return Codes |
| Cargo, linker, and make wiring for a downstream project | Build Integration |