Grounded in source
Every claim is traced to the xahaud repository (branch dev) - hook/extern.h, hook/error.h, hook/macro.h, the execution engine, and the test-suite example hooks.
Small WebAssembly programs attached to accounts. They run on-ledger when a transaction touches the account, read the originating transaction and ledger, keep persistent state, emit transactions, and accept or rollback.
Who this is for: developers writing Hook smart contracts in C, and anyone who needs an accurate reference for the Hook API functions, their error codes, and the execution model.
| Document | Description |
|---|---|
| Overview | Conceptual foundation: what Hooks are, entry points, execution modes, environment limits, and the typical processing flow. |
| Execution Order | Hook chains and the order hooks run in for one transaction: strong, weak, and callback passes, the reserved argument, and the chain-control APIs. |
| TSH | Transactional Stake Holders: strong vs. weak TSH, the two-condition gate for weak-TSH ("collect call") execution, and a per-transaction-type TSH table. |
| Hook Fees | Deployment, reserve, execution, and emitted-transaction costs in one place: what you pay, when, and who pays it. |
| XFL | XFL concept page: the fixed-precision floating-point format's bit encoding, valid range, and relationship to the ledger's Amount format. |
| NOP Bytes (0x99) | The 0x99 NOP byte Xahau's deserializer skips: its rules and limits, which Hook APIs honor it, and how to use it for optional and variable-length fields in an emitted-transaction template. |
| Compiling Hooks | From C to an installable WASM module: what the SetHook validator enforces, the recommended hooks-compiler toolchain, and the install-rejection log codes. |
| Validating Hooks | Check a compiled module with the hook_validate RPC before installing it: availability, request and response, and reading the guard checker's log. |
| Best Practices | Practical guidance: guarding loops, buffer sizing, state and reserve management, error handling. |
| SetHook Fields | SetHook fields that control hook triggering and permissions: HookOn, HookOnIncoming, HookOnOutgoing, HookCanEmit, HookName. |
| Helper Macros | Helper macros from hook/macro.h: control flow, guards, buffer helpers, integer conversion, comparison. |
| Tools | Community tooling for building Hooks: the hooks-compiler build tool, the Transaction Builder code generator, and the Binary Visualizer. |
| Other Languages | Writing hooks in Rust, Zig, AssemblyScript, or hand-written WAT: how to satisfy the validator's contract from a non-C toolchain. |
| Glossary | Alphabetical glossary of Hook terminology (Slot, Keylet, XFL, Namespace, Grant, Burden, TSH, and more). |
| Group | Description |
|---|---|
| Control APIs | Control functions: _g, accept, rollback, hook_account, hook_hash, hook_param, hook_param_set, hook_again, hook_skip, hook_pos. |
| Transaction APIs | Originating-transaction functions: otxn_field, otxn_id, otxn_type, otxn_slot, otxn_param, otxn_burden, otxn_generation. |
| State APIs | Hook state: state, state_set, state_foreign, state_foreign_set. |
| Slot APIs | The slot system: slot_set, slot*, meta_slot, xpop_slot. |
| Ledger APIs | Ledger info: ledger_*, fee_base. |
| Emit APIs | Emitting transactions: etxn_*, prepare, emit. |
| Float & Amount APIs | XFL floating-point math and amount serialization: float_*. |
| Utility APIs | Cryptography, address conversion, and keylet computation: util_*. |
| STO APIs | Serialized-object (STO) inspection/editing: sto_*. |
| Trace APIs | Debug tracing: trace*. |
| Document | Description |
|---|---|
| Payment Filter | Worked example: inspect an incoming Payment and accept or rollback. |
| State Counter | Worked example: read/increment/write a counter in hook state. |
| Emitted Transaction | Worked example: reserve, prepare, and emit a transaction. |
| Foreign State | Worked example: read another account's state via state_foreign. |
| Memo Routing | Worked example: route behavior based on transaction memos/parameters. |
For newcomers, read in this order:
hook_validate, and install it.Keep Glossary and Helper Macros open alongside the above; both are lookup references rather than linear reading.
Experienced developers can jump straight to the relevant api-reference/* page. Each function is documented with its exact C signature from hook/extern.h, its parameters, return convention, and error codes. The full error-code table lives in Overview and is repeated per function where relevant.
These documents were derived from the developer-facing Hook API headers (repo root https://github.com/Xahau/xahaud):
hook/extern.h — canonical developer-facing declarations of all API functions.hook/error.h — developer-facing error #defines.hook/macro.h — helper macros.hook/hookapi.h — top-level include; KEYLET_* and COMPARE_* constants.hook/sfcodes.h, hook/tts.h, hook/ls_flags.h, hook/tx_flags.h — field, transaction-type, and flag codes.The hook_return_code enum, limits, keylet codes, exit types, HookSet log codes, SetHook operations/flags, guard-validation rules, amendment gating (featureHooksUpdate1, featureHooksUpdate2), and the Hook execution engine itself round out the picture, and the example hooks referenced throughout this doc set come from the project's own test suite.
The consolidated, cross-checked inventory these docs build on is .claude/plans/hook-docs/api-inventory.md.
hook/macro.h)