Skip to content

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 most max_slots = 255 slots per hook execution (Enum.h). Requesting a slot when none are free returns NO_FREE_SLOTS (-6).
  • Slot 0 is special as an argument: passing 0 for 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:
    1. slot_set loads an object from a keylet (34 bytes) or a transaction id (32 bytes) into a slot.
    2. slot_subfield / slot_subarray drill into that slot, placing a subfield or array element into another slot.
    3. slot, slot_size, slot_count, slot_type, and slot_float read the slotted data.
    4. slot_clear frees 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

FunctionPurpose
slot_setLoad a ledger object or transaction into a slot.
slotWrite a slot's serialized contents to memory (or return as int64_t).
slot_sizeByte size of the data in a slot.
slot_clearFree a slot.
slot_countNumber of elements in a slotted array.
slot_subfieldExpand a subfield of a slotted object into a new slot.
slot_subarrayExpand an array element of a slotted array into a new slot.
slot_typeReturn the field type of a slot (and whether an amount is XRP).
slot_floatInterpret a slotted amount as an XFL value.
meta_slotLoad the originating transaction's metadata into a slot.
xpop_slotLoad an XPOP's inner transaction and metadata into two slots.