Skip to main content
Use the C SDK when you want direct access to the Thru VM and the lowest-level program development workflow.

Install

Before using the C SDK, install the CLI and development prerequisites through Set Up Thru DevKit. Then make sure you have installed both the toolchain and the C SDK with thru-cli:
thru-cli dev toolchain install
thru-cli dev sdk install c
This gives you the RISC-V toolchain plus the installed C SDK headers and build integration used by downstream C programs. After installation, the C SDK lands under ~/.thru/sdk/c, and the downstream build hook lives at ~/.thru/sdk/c/thru-sdk/thru_c_program.mk.

Verify your install

test -d ~/.thru/sdk/c
test -f ~/.thru/sdk/c/thru-sdk/thru_c_program.mk
test -d ~/.thru/sdk/toolchain/bin
test -x ~/.thru/sdk/toolchain/bin/riscv64-unknown-elf-gcc || test -x ~/.thru/sdk/toolchain/bin/riscv64-none-elf-gcc

Start here

If you need…Open this page
A compact mental model of how a program is laid out and exitsProgram Structure
The rules of the Thru VM C environment and what differs from normal user-space CVM C Environment
Which header to include and which macros/helpers are foundationalHeaders and Entry Points
How to read accounts, transaction fields, block context, and shadow stack dataAccounts and Transaction Context
What each syscall does and when to use itSyscalls
How tsys_invoke and tsdk_invoke_auth_t workCross-Program Invocation
How proof headers and proof bodies are laid outState Proofs
How success, revert, syscall, and CPI errors should be handledError Handling and Return Codes
How to wire the installed SDK into a downstream C projectBuild Integration
Short, copyable program patternsCommon Patterns
The main failure modes agents should avoidCommon Gotchas

When to use it

Use the C SDK when you want to…Why it fits
Write on-chain programs that run directly inside the Thru VMThe SDK exposes raw transaction context, account pointers, syscalls, and VM-oriented helpers.
Control account mutation and CPI explicitlyThe syscall layer gives you direct access to create, resize, transfer, compress, decompress, and invoke operations.
Minimize abstraction and stay close to runtime layoutThe public structs and helper functions mirror transaction, account, block, shadow stack, and state proof shapes closely.

Core entry points

Entry pointWhat it provides
#include <thru-sdk/c/tn_sdk.h>Main umbrella include for most programs.
#include <thru-sdk/c/tn_sdk_syscall.h>Explicit syscall wrappers for account mutation, CPI, logging, events, and exit.
#include <thru-sdk/c/tn_sdk_txn.h>Transaction, account metadata, block context, shadow stack, and state proof structs.
thru_c_program.mkThe downstream makefile entrypoint for compiling against the installed SDK.

Additional headers

HeaderWhat it provides
#include <thru-sdk/c/tn_sdk_sha256.h>SHA-256 hashing (incremental and one-shot).
#include <thru-sdk/c/tn_crypto.h>BLS12-381 cryptography: key generation, signing, verification, aggregation. Available when the installed toolchain includes libblst.a and headers.
#include <thru-sdk/c/tn_rle.h>Run-length encoding for compact bitset representation.
#include <thru-sdk/c/tn_sdk_types.h>Base public types (tn_pubkey_t, tn_hash_t, tn_signature_t).
#include <thru-sdk/c/tn_sdk_base.h>Low-level alignment, scratch-allocation, and utility macros.