Appearance
Ledger and Slot APIs
This page documents the seventeen ledger-and-slot Hook APIs: the slot family (an efficient handle system for transaction and ledger-object data), the metadata/XPOP slot loaders, and the ledger info family (sequence, times, hashes, nonces, and keylet enumeration). The slot family is documented here; the ledger-info family has its own page, Ledger APIs.
All signatures are copied verbatim from hook/extern.h. Return codes reference the shared error table in ../../glossary.md; values come from include/xrpl/hook/Enum.h and hook/error.h. Implementations live in src/xrpld/app/hook/detail/HookAPI.cpp (core logic) and src/xrpld/app/hook/detail/applyHook.cpp (WASM-facing wrappers).
The slot system
Serialized ledger objects and transactions can be large. Rather than copy a whole object into WASM memory to read one field, a hook loads the object into a slot — a numbered, server-side handle — and then drills into it.
- A slot holds a parsed serialized object (an
STObject,STArray, or a leaf field). There are at mostmax_slots= 255 slots per hook execution (Enum.h). Requesting a slot when none are free returnsNO_FREE_SLOTS(-6). - Slot 0 is special as an argument: passing
0for a destination slot means "allocate any free slot for me", and the chosen slot number is returned. Passing a specific number targets that slot (overwriting whatever was there). - Typical lifecycle:
slot_setloads an object from a keylet (34 bytes) or a transaction id (32 bytes) into a slot.slot_subfield/slot_subarraydrill into that slot, placing a subfield or array element into another slot.slot,slot_size,slot_count,slot_type, andslot_floatread the slotted data.slot_clearfrees a slot when you are done (or you simply let execution end).
Keylets for slot_set are usually built with util_keylet, which produces the 34-byte serialized keylet these functions expect.
Index
| Function | Purpose |
|---|---|
slot_set | Load a ledger object or transaction into a slot. |
slot | Write a slot's serialized contents to memory (or return as int64_t). |
slot_size | Byte size of the data in a slot. |
slot_clear | Free a slot. |
slot_count | Number of elements in a slotted array. |
slot_subfield | Expand a subfield of a slotted object into a new slot. |
slot_subarray | Expand an array element of a slotted array into a new slot. |
slot_type | Return the field type of a slot (and whether an amount is XRP). |
slot_float | Interpret a slotted amount as an XFL value. |
meta_slot | Load the originating transaction's metadata into a slot. |
xpop_slot | Load an XPOP's inner transaction and metadata into two slots. |
Related documents
- ../../README.md — documentation index.
- ../../overview.md — hook execution model and lifecycle.
- ../../glossary.md — full error-code and term reference.
- ../../macros.md —
SBUF,GUARD, and buffer helpers. - ../../best-practices.md — slot budgets and iterating ledger objects.
- Ledger APIs —
fee_base,ledger_seq,ledger_nonce, and the rest of the ledger-info family. - control.md —
hook_againand the strong/weak execution model. - transaction.md —
otxn_slot,otxn_field, and originating-txn access. - state.md — persistent state read/write.
- emit-and-etxn.md —
etxn_fee_base,etxn_nonce, and emission. - float-and-amount.md — XFL math for
slot_floatvalues. - utility.md —
util_keyletfor building the keyletsslot_set/ledger_keyletconsume. - ../../examples/emitted-transaction.md — reading slots and emitting.
- ../../examples/memo-routing.md — drilling arrays and subfields.