Skip to content

Transaction APIs

This page documents the seven transaction Hook APIs: the otxn_* family, which reads the originating transaction — the transaction that caused the hook to run — along with its lineage (burden and generation) and its carried parameters.

All signatures are copied verbatim from hook/extern.h. Return codes reference the shared error table in ../../glossary.md; the values quoted below come from include/xrpl/hook/Enum.h and hook/error.h. The implementations are in src/xrpld/app/hook/detail/HookAPI.cpp (the HookAPI::otxn_* methods) and their WASM wrappers in src/xrpld/app/hook/detail/applyHook.cpp.


The originating transaction

Every hook execution has exactly one originating transaction (often abbreviated otxn). For a strong or weak execution it is the transaction currently being processed against the ledger — the transaction whose account, or a party to it (a TSH), has a hook installed. The otxn_* functions are the hook's window onto that transaction: its type, its id, its individual fields, and any HookParameters it carries.

The originating transaction is not the same as the hook account. The hook account (see hook_account) is the account the hook is installed on; the originating transaction's sender is otxn_field(sfAccount). In a payment hook installed on the receiver, for example, hook_account is the receiver and otxn_field(sfAccount) is the sender.

During a callback (cbak), the originating transaction can shift. When a hook emits a transaction and that emitted transaction later fails, the hook's cbak entry point is invoked with the low bit of its reserved argument set. In that case the server populates an internal emitFailure object with the emitted transaction (read back from the emitted-txn ledger directory), and the otxn_* functions read from that transaction instead of the incoming one (verified in applyHook.cpp, where emitFailure is set to the emitted STObject when isCallback && (wasmParam & 1)). Concretely:

  • otxn_type returns the emitted transaction's sfTransactionType.
  • otxn_field reads fields from the emitted transaction.
  • otxn_id with flags == 0 returns the emitted transaction's stored hash (sfTransactionHash); with a non-zero flags it returns the computed transaction id.

When cbak is invoked for a successful emitted transaction (low bit clear), emitFailure is not set and the otxn_* functions behave as in a normal execution. See hook_again and ../../overview.md for the strong/weak/callback execution model.


Index

FunctionPurpose
otxn_typeTransaction type of the originating transaction.
otxn_idWrite the originating transaction's hash/ID.
otxn_fieldWrite (or return) a field of the originating transaction.
otxn_paramRead a HookParameter carried on the originating transaction by key.
otxn_slotLoad the whole originating transaction into a slot.
otxn_burdenBurden value of the originating transaction.
otxn_generationEmit-generation counter of the originating transaction.