---
title: Chaining
description: Chain multiple hooks together to do more useful tasks
---
import { Aside } from '@astrojs/starlight/components';

<Aside type="tip" title="Hook Design Philosophy">
_Each Hook should do one thing, and do it really well._
</Aside>

### History

In the early days of Hooks it was only possible to install one Hook per account. This meant users were forced to produce omnibus Hooks if they wanted to do more than one thing: for example offset carbon and firewall at the same time.

This was counter to the Hook Design Philosophy, so Hook Chaining was introduced.

### Chaining

A Hook Chain is a sequence of up to **10** Hooks installed on an Xahau account.

* A Hook Chain executes successfully when every Hook in the chain has been individually executed and subsequently calls [accept](/docs/hooks/functions/control/accept).
* Each chain's execution starts at chain position 0 and ends at chain position 9. If a position is blank (because it was never filled or because the hook that was installed there has been removed) then that position is skipped and treated as successful.
* In order for a transaction to succeed, both ends of the transaction (sending side and receiving side) must have executed successfully. This means if there is a Hook Chain installed on both sides, then both Hook Chains must execute successfully for the transaction to succeed.

Hooks are installed into the chain using the [SetHook Transaction](/docs/hooks/concepts/sethook-transaction). When they are installed, the installer may specify install-time [Parameters](/docs/hooks/concepts/parameters) which may change the behaviour of the installed Hook.

<figure>
![Example: Execution flow for a transaction passing through two Hook Chains](/assets/spaces_m6f29os4wP16vCS4lHNh_uploads_0OucxySTRinbe13SITJT_5561b32-sethook-Page-3.png)
<figcaption>*Example: Execution flow for a transaction passing through two Hook Chains*</figcaption>
</figure>

### Chain Manipulation

In addition to the _install-time_ operations specified in the [SetHook Transaction](/docs/hooks/concepts/sethook-transaction), Hooks have some runtime control over chain execution:

* A Hook may determine its own `HookHash` by calling [hook_hash](/docs/hooks/functions/hook-context/hook_hash).
* A Hook may determine its location in the Hook Chain using [hook_pos](/docs/hooks/functions/hook-context/hook_pos).
* A Hook may skip (or re-enable) another Hook further down the chain using [hook_skip](/docs/hooks/functions/hook-context/hook_skip).
* A Hook may modify the [Parameters](/docs/hooks/concepts/parameters) of a Hook further down the chain using [hook_param_set](/docs/hooks/functions/hook-context/hook_param_set).

### Weak Executions

Hook Chains are [Strongly Executed](/docs/hooks/concepts/weak-and-strong). However any Hook in any chain may flag that it requires a second, Weak Execution by calling [hook_again](/docs/hooks/functions/hook-context/hook_again). If all Hook Chains execute successfully then the originating transaction is applied. Once the originating transaction has been applied any Weak Executions may happen, in the following order:

1. `cbak` execution if this was an Emitted Transaction.
2. Weak Transactional Stake Holders who have opted in to allow a [Collect Call](/docs/hooks/concepts/collect-call). Execution order is first-come first-serve according to the event that caused the TSH to be flagged (such as pathing).
3. Any _Again as Weak_ (AAW) Hooks. Execution order for AAW is first numerically according to Account ID then numerically according to Hook position.
