How many Hooks can you have per XRPL account?
Last updated:
An XRPL account can have a maximum of 4 Hooks attached simultaneously, with each Hook serving different purposes or triggering on different transaction types.
Hook Limit Specifications:
Maximum Hooks per Account: 4 Each Hook Can Be: - Up to 64 KB in size - Configured for specific transaction types - Enabled or disabled independently - Updated or removed
Total Capacity: 4 Hooks × 64 KB = 256 KB of executable logic per account
Why Limit to 4 Hooks?
1. Performance Considerations: - Each transaction triggers all applicable Hooks - Validators must execute all Hooks before consensus - 4 Hooks keeps execution time reasonable - Maintains 3-5 second ledger close time
2. Complexity Management: - More Hooks = more complex interactions - 4 is enough for modular design - Prevents account logic from becoming unmaintainable
3. Resource Protection: - Limits validator computational burden - Prevents resource exhaustion attacks - Fair network access for all accounts
How Multiple Hooks Work:
Execution Order:
Hooks execute in defined order: 1. Hook 0 (highest priority) 2. Hook 1 3. Hook 2 4. Hook 3 (lowest priority)
Each Hook can: - Accept transaction (continue to next Hook) - Reject transaction (abort, no state changes) - Modify transaction parameters - Store state data
Hook Composition Patterns:
Pattern 1: Modular Functionality ``` Hook 0: Authentication/permission checking Hook 1: Business logic execution Hook 2: Fee calculation and distribution Hook 3: Audit logging and event emission ```
Pattern 2: Transaction Type Routing ``` Hook 0: Handle Payment transactions Hook 1: Handle TrustSet transactions Hook 2: Handle OfferCreate transactions Hook 3: Handle NFT transactions ```
Pattern 3: Layered Security ``` Hook 0: Rate limiting Hook 1: Whitelist/blacklist checking Hook 2: Amount threshold validation Hook 3: Multi-sig logic ```
Hook Configuration:
Each Hook Has: - Namespace: Unique identifier - Trigger Conditions: Which transaction types activate it - Parameters: Configuration data - State: Persistent storage allocation
Setting Multiple Hooks:
```javascript // Example: SetHook transaction { "Account": "rAccount...", "TransactionType": "SetHook", "Hooks": [ { "Hook": { "HookHash": "ABC123...", // Hook 0 "CreateCode": "...", "HookOn": "0xFFFF...", // All transaction types "HookNamespace": "..." } }, { "Hook": { "HookHash": "DEF456...", // Hook 1 "HookOn": "0x0010...", // Only Payments // ... } } // ... up to 4 total ] } ```
Managing Hook Slots:
Adding Hooks: - Install to next available slot (0-3) - Can specify exact slot position - Previous Hook in slot gets overwritten
Removing Hooks: - Set specific slot to null/empty - Other Hooks remain active - Can remove all 4 to clear account
Updating Hooks: - Replace Hook in specific slot - Can update one Hook without touching others - Atomic operation (all or nothing)
Hook Interaction:
Can Hooks Communicate?
Yes, via: - Shared state: Hooks on same account can read/write common state - Parameters: Pass data between Hooks - Transaction metadata: One Hook can set data for next Hook
Execution Flow: ``` Transaction arrives → Hook 0 executes → accept/reject/modify → Hook 1 executes → accept/reject/modify → Hook 2 executes → accept/reject/modify → Hook 3 executes → accept/reject/modify → Transaction processed if all Hooks accepted ```
Use Cases for Multiple Hooks:
DeFi Protocol: - Hook 0: Validate swap parameters - Hook 1: Calculate optimal route - Hook 2: Execute swap and update pools - Hook 3: Distribute fees to liquidity providers
Enterprise Treasury: - Hook 0: Approval workflow enforcement - Hook 1: Compliance checking (sanctions screening) - Hook 2: Budget limits and controls - Hook 3: Audit trail and reporting
NFT Marketplace: - Hook 0: Verify NFT ownership - Hook 1: Check payment amount - Hook 2: Execute transfer - Hook 3: Calculate and distribute royalties
Cost Implications:
Transaction Fees: - Base XRPL fee: 0.00001 XRP - Each Hook adds computational cost - More Hooks = slightly higher fee - Still negligible (fractions of a cent)
State Storage Fees: - Each Hook's state counts as ledger objects - Owner reserve requirements apply - Plan for reserve costs when designing multi-Hook systems
Limits Summary:
| Limit Type | Value | Rationale | |------------|-------|-----------| | Hooks per account | 4 | Performance & complexity management | | Hook code size | 64 KB | Efficiency & quick execution | | Total logic | 256 KB | 4 × 64 KB combined capacity | | Instruction count | ~500K | Execution time constraint | | State storage | Variable | Based on reserve requirements |
Future Evolution:
As XRPL scales and validator hardware improves: - Hook limit could increase (via amendment) - Instruction limits could expand - More complex DeFi becomes viable
Current limits represent conservative, battle-tested constraints that ensure network stability while enabling powerful functionality.
*Last updated: February 2026*