mobileRumblefishLogo
Menu
Exploring Hooks on the XRPL: A Developer’s Journey Beyond the EVM

Exploring Hooks on the XRPL: A Developer’s Journey Beyond the EVM

Mon, Dec 1, 20256 min read

Category: Blockchain

I believe it’s good to challenge yourself, step outside your comfort zone, and do some not-so-easy theoretical mental exercises. Sometimes for fun, sometimes because you have to, and sometimes both. And that’s exactly how I, an EVM-specialized developer, ended up on a new planet called the XRPL. Initially, the mission seemed simple: create some tokens, then build a type of AMM with extra features, e.g., a min-max swap amount per account restriction. Easy peasy… BUT - the challenge was to do it on the XRPL, the XRP Ledger. So in this article, I invite you to join me on this journey of discovering features and possibilities of the XRP Ledger.

Disclaimer: I’m aware of the XRPL EVM sidechain, which is the natural way to go for any EVM-based developer. I also know that Hooks on XRPL are only live on testnet (as of November 2025). But for the sake of curiosity, let’s check this out anyway.

What are Hooks? What’s the idea behind them?

The XRPL Hooks documentation states: “Hooks add smart contract functionality to the XRP Ledger: layer one custom code to influence the behaviour and flow of transactions. Hooks are small, efficient pieces of code being defined on an XRPL account, allowing logic to be executed before and/or after XRPL transactions.” And honestly, that’s exactly it. Hooks bring smart-contract-like behavior to XRPL accounts and let you run logic before and/or after transactions. Examples range from simple, like “reject payments < 10 XRP”, to more advanced rules like automatically routing 10% of every outgoing payment to a savings account.

So how do Hooks work under the hood?

First of all, Hooks are WebAssembly modules “installed” on a specific account. That means they can be written in any language that compiles to WebAssembly, though in practice, they’re typically written in C. Hooks in the XRPL world get attached to an account through a SetHook transaction. Once you’ve plugged a Hook in, it basically acts like a smart mini-guardian for that account. It can:

  • Step in and either allow or block incoming and outgoing transactions,
  • Maintain its own internal state and logic to react based on past events, and
  • Even fire off brand-new transactions on behalf of the account.

Hooks on XRPL aren’t Turing-complete by design - no unlimited loops allowed. If you use a loop, you must set a strict maximum. That’s where guards come in. A guard sits at the top of a loop and tells the XRPL the highest number of iterations it could ever run. Maybe it usually loops twice, maybe in extreme cases 500 times - then the guard sets the maximum to 500. XRPL uses this to predict worst-case execution time and calculate the Hook’s fee, keeping everything neat, fast, and predictable.

Cool, but what if a single Hook isn’t enough? Can I combine a few?

You can - and that’s called a Hook Chain. It’s basically a lineup of up to 10 Hooks on an XRPL account. When a transaction comes in, the chain runs from slot 0 to slot 9, skipping empty slots and treating them as a clean pass. For the transaction to succeed, both the sender and receiver must fully pass their respective Hook Chains. Hooks are added using the SetHook transaction, and when you install one, you can pass parameters that tweak its behavior.

OK, enough theory. How do I install a Hook?

Simply use the SetHook transaction type. Here’s an example (taken from the official docs)

{ Account: "r4GDFMLGJUKMjNhhycgt2d5LXCdXzCYPoc", TransactionType: "SetHook", Fee: "2000000", Hooks: [ { Hook: { CreateCode: fs.readFileSync('accept.wasm').toString('hex').toUpperCase(), HookOn: '0000000000000000', HookNamespace: addr.codec.sha256('accept').toString('hex').toUpperCase(), HookApiVersion: 0 } } ] }

Is it also possible to set the array of hooks within a single transaction, like so (the same source as above):

{ Account: "r4GDFMLGJUKMjNhhycgt2d5LXCdXzCYPoc", Account: "r4GDFMLGJUKMjNhhycgt2d5LXCdXzCYPoc", TransactionType: "SetHook", Hooks: // This is the Hooks Array [ { Hook: { ... } }, // HookSet Object (position 0) { Hook: { ... } }, { Hook: { ... } }, { Hook: { ... } }. // HookSet Object (position 3) ] }

You can also update or delete Hooks from an account using the same transaction type. Aaaaand that’s pretty much it! This is just an overview, as there’s a lot more to explore in the mysterious world of Hooks. From this point on, I encourage you to dive deeper yourself. Unfortunately, as mentioned earlier, Hooks don’t seem to be actively developed anymore, with the XRPL team shifting focus toward the EVM sidechain. That’s just my speculation, but regardless, it was really fun to get familiar with this concept. Hope you enjoyed the ride too!

Oskar Karcz
Oskar Karcz

Blockchain Developer & Content Guru

Categories
Follow Us