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 withthru-cli:
~/.thru/sdk/c, and the downstream build hook lives at ~/.thru/sdk/c/thru-sdk/thru_c_program.mk.
Verify your install
Start here
| If you need… | Open this page |
|---|---|
| A compact mental model of how a program is laid out and exits | Program Structure |
| The rules of the Thru VM C environment and what differs from normal user-space C | VM C Environment |
| Which header to include and which macros/helpers are foundational | Headers and Entry Points |
| How to read accounts, transaction fields, block context, and shadow stack data | Accounts and Transaction Context |
| What each syscall does and when to use it | Syscalls |
How tsys_invoke and tsdk_invoke_auth_t work | Cross-Program Invocation |
| How proof headers and proof bodies are laid out | State Proofs |
| How success, revert, syscall, and CPI errors should be handled | Error Handling and Return Codes |
| How to wire the installed SDK into a downstream C project | Build Integration |
| Short, copyable program patterns | Common Patterns |
| The main failure modes agents should avoid | Common 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 VM | The SDK exposes raw transaction context, account pointers, syscalls, and VM-oriented helpers. |
| Control account mutation and CPI explicitly | The syscall layer gives you direct access to create, resize, transfer, compress, decompress, and invoke operations. |
| Minimize abstraction and stay close to runtime layout | The public structs and helper functions mirror transaction, account, block, shadow stack, and state proof shapes closely. |
Core entry points
| Entry point | What 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.mk | The downstream makefile entrypoint for compiling against the installed SDK. |
Additional headers
| Header | What 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. |