Skip to content

Hook

[Source]

(Added by the Hooks amendment.)

A Hook object describes a smart contract, which can be triggered by a transaction to perform predefined operations. The operations are defined by the Hook creator and can interact with the ledger and transactions.

{
"Account": "rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo",
"OwnerNode": "0000000000000000",
"PreviousTxnID": "5463C6E08862A1FAE5EDAC12D70ADB16546A1F674930521295BC082494B62924",
"PreviousTxnLgrSeq": 6,
"Hooks": [
{
"HookHash": "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
"HookParameters": []
}
],
"LedgerEntryType": "Hook",
"index": "49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0"
}

A Hook object has the following fields:

FieldJSON TypeInternal TypeRequired?Description
AccountStringAccountYesThe account that created the Hook.
OwnerNodeStringUInt64YesA hint indicating which page of the owner’s directory links to this object, in case the directory consists of multiple pages.
PreviousTxnIDStringHash256YesThe ID of the transaction that most recently modified this object.
PreviousTxnLgrSeqNumberUInt32YesThe ledger index of the ledger that contains the transaction that most recently modified this object.
HooksArrayArrayYesAn array of hook objects. Each object has the following fields: HookHash, CreateCode, HookGrants, HookNamespace, HookParameters, HookOn, HookOnIncoming, HookOnOutgoing, HookCanEmit, HookName, HookApiVersion, Flags.
LedgerEntryTypeStringUInt16YesThe value 0x0043, mapped to the string Hook, indicates that this object is a Hook object.

The following fields are used in the hook object:

FieldJSON TypeInternal TypeDescription
HookHashStringHash256The hash of the hook.
CreateCodeStringBlobThe hex-encoded WebAssembly binary (WASM) that defines the hook’s logic. Present when the hook was installed with inline code rather than referencing an existing HookDefinition object.
HookGrantsArrayArrayAn array of grant objects specifying which accounts are permitted to set or modify this hook on the hook account’s behalf.
HookNamespaceStringHash256A 32-byte (64 hex character) namespace that segregates this hook’s state data from other hooks on the same account. Must be unique per hook slot.
HookParametersArrayArrayThe parameters of the hook.
HookApiVersionNumberUInt16The version of the Hooks API used by this hook. Determines which hook API functions are available to the WASM binary at runtime.
HookOnStringHash256The transaction type(s) on which the hook is triggered. Mutually exclusive with HookOnIncoming/HookOnOutgoing.
HookOnIncomingStringHash256(HookOnV2) Same syntax as HookOn. Triggers the hook on transactions originating from another account. Mutually exclusive with HookOn.
HookOnOutgoingStringHash256(HookOnV2) Same syntax as HookOn. Triggers the hook on transactions originating from the Hook account itself. Mutually exclusive with HookOn.
HookCanEmitStringHash256Same syntax as HookOn. Controls which transaction types the hook is allowed to emit. If absent, the hook may emit any transaction type.
HookNameStringBlob(NamedHooks) UTF-8 string (4–16 bytes, hex-encoded) assigned to this hook slot. When present, the hook only executes if the triggering transaction carries a matching top-level HookName field.
FlagsNumberUInt32Additional flags for the hook.

The ID of a Hook object is the SHA-512Half of the following values, concatenated in order:

  • The Hook space key (0x0048)
  • The AccountID of the sender of the SetHook transaction that created the Hook object