HTLC & Preimage API
Hydra App settles swaps two ways: through payment channels (the default) and, since 2026-06-11, on-chain via HTLCs (Hash-Time-Locked Contracts). This page covers the two services that expose the on-chain path:
PreimageService(namespacepreimage) — settle a revealed preimage. Two RPCs, one per facet:SettlePreimagefor channel legs (this replacedNodeService.RegisterPreimage) andSettleHtlcPreimagefor on-chain HTLC legs.HtlcService(namespacehtlc) — low-level on-chain HTLC operations: lock, claim, refund, verify, watch, and external-signer transaction builders.
These are advanced, low-level surfaces. Most integrations never call
HtlcServicedirectly — they opt a swap leg on-chain viaSwapRequest.settlement/ the orderbookOrderSettlementand let the node drive the HTLCs, observing progress through swap milestones andSubscribeHtlcEvents. Reach forHtlcServicewhen you run your own signer or build cross-chain flows by hand.For field-level detail always consult the authoritative schema —
htlc.proto,preimage.proto,currency.proto.
Channel vs on-chain settlement
Every swap has a sending leg (you → orderbook hub) and a receiving leg (hub → you). Each leg settles independently through either a channel or an on-chain HTLC.
- Channel (default). Requires an active channel for that currency. Instant, cheap, no on-chain footprint — the historical Hydra path.
- On-chain HTLC. Lets you trade a currency you hold on-chain, with no channel for it. Slower and costs chain fees, but needs no pre-funded channel.
You express the preference per order as an OrderSettlement (from currency.proto), signed into the order:
| Field | Type | Meaning |
|---|---|---|
sending | LegSettlement | How you send to the hub |
receiving | LegSettlement | How you receive from the hub |
route_filter | uint32 (optional) | Taker-only route-wide method bitmask: bit 0 = Channel, bit 1 = On-chain. Absent = no constraint. Must be absent on a resting maker order. |
receiving_claim | ReceivingClaim | (2026-10-29) Who claims your receive when it settles on chain: required whenever receiving may settle on chain, unset otherwise. |
LegSettlement values: CHANNEL (0, the default when OrderSettlement is absent), ONCHAIN (1), CHANNEL_OR_ONCHAIN (2 — the orderbook picks, preferring channel).
ReceivingClaim values: RECEIVING_CLAIM_RECIPIENT (1) — your node claims the hub's lock itself, paying the claim's fee from its own wallet, and the swap charges nothing for the claim; RECEIVING_CLAIM_VENUE (2) — the venue claims it for you once the swap's secret is out, so you need not stay online, and the swap charges the claim's estimated cost times the asset's multiple the venue publishes; your node claims itself only if the venue's claim has not landed in time. The venue offers this only on the assets it lists; RECEIVING_CLAIM_UNSPECIFIED (0) is what a receive in a channel carries.
Rules & mechanics:
- On-chain is valid only for taker orders (
market_order/swap_order/Swap/SimpleSwap). Resting maker orders (limit orders) are channel-only. - The on-chain refund/claim addresses are not declared in the order. The node supplies them later, at the orderbook's
PrepareSwaphandshake.OrderSettlementis a pure method selector. - Once matched, per-hop on-chain details surface on the route as
SwapHop.sending_onchain/receiving_onchain, and progress arrives as simple-swap milestones. - The atomic-swap invariant is unchanged: the receiving leg's HTLC, when claimed, reveals the preimage, which then unlocks the sending leg. On-chain, that preimage becomes public on-chain when the counterparty claims.
Settling a revealed preimage
A revealed preimage S can unlock value on two independent facets of a network's node — held channel hashlock payments, and on-chain HTLCs paying this node under sha256(S). Since 2026-08-01 each facet has its own RPC, because they settle independently: they fail independently, and only the on-chain one broadcasts transactions and therefore costs a fee.
On a network with both facets, drive both RPCs. If you relied on
SettlePreimagealso sweeping on-chain HTLCs (its 2026-06-11 behavior), you must now also callSettleHtlcPreimage.
Settle Preimage
Namespace preimage. Added 2026-06-11 (replaced node.RegisterPreimage); narrowed to channel legs 2026-08-01.
Registers a revealed preimage and settles every channel leg it unlocks on the given network: persists it durably, claims held channel hashlock payments, and arms the on-chain settlement path. Idempotent. Costs no fee of its own — any resulting on-chain settlement is the channel's own path.
Method: SettlePreimage
| Name | Type | Required | Description |
|---|---|---|---|
network | Network | YES | Target network |
payment_preimage | string | YES | Hex-encoded preimage to settle |
Response: Empty.
This is the drop-in replacement for the removed
node.RegisterPreimage— same request fields. See Node API → Register Preimage (moved).
Settle HTLC Preimage
Added 2026-08-01.
Claims every on-chain HTLC the preimage unlocks on the given network: each one still Locked, paying this node, under sha256(preimage). Idempotent — an HTLC already claimed is simply no longer Locked.
Method: SettleHtlcPreimage
| Name | Type | Required | Description |
|---|---|---|---|
network | Network | YES | Target network |
payment_preimage | string | YES | Hex-encoded preimage whose hash the claimed HTLCs commit to |
fee_option | FeeOption | NO | Fee for the claim transactions. Absent = the network's default (medium) HTLC fee rate — the same default every other unpinned HTLC operation takes. |
Response:
| Field | Type | Description |
|---|---|---|
txids | string[] | One transaction id per HTLC claimed, in no particular order. Empty when the secret unlocks none here — that is a success, not an error. |
Each claim is its own transaction. One that cannot be built — already swept, expired and refunded, unfunded for its fee — is skipped rather than withholding the others, so a partial result is normal. Rejected with
FAILED_PRECONDITIONon a network with no on-chain HTLC facet.
import { PreimageServiceClient } from './proto/PreimageServiceClientPb'
import { SettlePreimageRequest, SettleHtlcPreimageRequest } from './proto/preimage_pb'
const preimage = new PreimageServiceClient('http://localhost:5003')
const network = { protocol: 1, id: '0a03cf40' }
const secret = '9f8e7d6c...'
// 1. Channel legs — no fee of its own.
const chan = new SettlePreimageRequest()
chan.setNetwork(network)
chan.setPaymentPreimage(secret)
await preimage.settlePreimage(chan, {})
// 2. On-chain HTLC legs — broadcasts one claim tx per HTLC.
const onchain = new SettleHtlcPreimageRequest()
onchain.setNetwork(network)
onchain.setPaymentPreimage(secret)
const res = await preimage.settleHtlcPreimage(onchain, {})
console.log('claimed:', res.getTxidsList()) // [] = nothing to claim here
HtlcService RPCs
Namespace htlc. Works across Bitcoin (P2WSH / Taproot) and EVM / Tron (HtlcFactory contract). One-line summaries below; see htlc.proto for full request/response shapes.
Node-signed lock / claim / refund
The node signs and broadcasts, keying the refund branch to itself.
| RPC | Purpose |
|---|---|
CreateHtlc | Lock funds into a new on-chain HTLC. Returns the Htlc + the broadcast lock txid. |
BatchCreateHtlcs | Lock several HTLCs in one transaction (where the protocol supports it). |
ClaimHtlc | Claim an HTLC by revealing the preimage. |
RefundHtlc | Refund an expired HTLC back to the sender. |
External-signer transaction builders
The node builds an unsigned transaction (calldata / PSBT); you own signing and broadcast. Unlike CreateHtlc, these key the refund branch to a refund_address you supply.
| RPC | Purpose |
|---|---|
CreateHtlcLockTx | Build an unsigned HTLC lock transaction for an external signer. (2026-10-29) On Bitcoin, hold_seconds holds the coins the lock spends until it is sent, given up or the time passes, as for a send; the lock's own timelock passing ends the hold sooner. |
CreateHtlcClaimTx | Build an unsigned HTLC claim transaction. |
CreateHtlcRefundTx | Build an unsigned HTLC refund transaction. |
CreateHtlcSettlementTx | Build an unsigned settlement tx spending an HTLC to a fixed output, for pre-signing. Takes kind — a SettlementKind: SETTLEMENT_KIND_CLAIM (1) spends the claim branch, SETTLEMENT_KIND_REFUND (2) the timeout branch — and output, where empty asks the node to pay the spending party's own key (the claim recipient or the refund sender) as a P2WPKH, for a caller that cannot construct chain addresses. UTXO-model protocols only (account-model settle permissionlessly → FAILED_PRECONDITION). |
BroadcastHtlcSettlement | Broadcast a user-pre-signed settlement tx, injecting the preimage for a claim. UTXO-model only. |
CreateHtlcSponsoredClaimTx | (2026-10-29) Build an unsigned claim of an HTLC for a sponsor to complete: a version 3 transaction paying the HTLC's whole value to output (empty: the claim key's own P2WPKH) and a zero-value pay-to-anchor output, with no fee. Its recipient signs it whole. UTXO-model only. |
CompleteSponsoredHtlcClaim | (2026-10-29) Complete a claim built by CreateHtlcSponsoredClaimTx and signed by its recipient: the node injects the preimage, builds its own child of the anchor paying, over the claim and itself, the rate that targets the next block, signs the child and broadcasts the two as one package. Returns the claim's txid. Refuses a claim of an HTLC the node does not know and one in any other shape or not signed whole. UTXO-model only. |
Each builder returns an HtlcTransactionRequest = an unsigned TransactionRequest plus the pre-computed Htlc(s) it creates or spends. (2026-10-29) On Bitcoin it also names the transaction's txid, which signing does not change and wallet.DiscardTransaction takes for a lock, and, for a lock built with hold_seconds, held_until (google.protobuf.Timestamp), the latest moment the hold on its coins lasts: it ends sooner when the lock is sent or given up, or when its timelock passes.
Fee estimates
| RPC | Purpose |
|---|---|
EstimateHtlcFees | (2026-10-29) What each on-chain step of an HTLC locking amount of asset_id costs on a network now, at fee_option: an HtlcFees of lock, claim, sponsored_claim and refund, in the network's native asset. Priced for an HTLC the node would lock from its own wallet; no HTLC needs to exist. |
Verify & read
| RPC | Purpose |
|---|---|
VerifyHtlc | Verify an on-chain HTLC matches an HtlcExpectation (recipient, hash, min amount, min timelock, refund key, required lock_type), seed the node's record, return the Htlc. |
BatchVerifyHtlcs | Verify many HTLCs at once. |
GetChainHtlc | Raw chain read of an HTLC by its lock transaction — no expectation checks, no persistence. Returns no HTLC when the chain can't produce it (unknown lock tx; unspent/hidden Bitcoin leaf). |
VerifyHtlcByLockTxid | Locate the HTLC output inside an attested funding tx, verify it, seed the record, return the Htlc (with its chain-native id). Entry point for an externally-funded HTLC whose outpoint the funder can't know in advance. UTXO-model only. |
DeriveHtlcAddress | The chain address the given HTLC parameters commit to — the address an external wallet pays to fund the HTLC. UTXO-model only. |
Keys & watching {#watch--unwatch}
| RPC | Purpose |
|---|---|
GetHtlcPubkey | The node's canonical HTLC public key on a network — the key its locks refund to and that counterparties lock to. |
GetUniqueHtlcPubkey | Reserve a fresh, unique HTLC public key (UTXO: never-reused per call; account-model: the single stable key). |
WatchHtlc | Watch an externally-locked HTLC the node didn't create, so its transitions arrive on SubscribeHtlcEvents. Fire-and-forget; optional abandon_at_unix_seconds and confirmation_depth. |
UnwatchHtlc | Stop observing an HTLC. Idempotent. |
Key types
The Htlc type
The unified on-chain HTLC snapshot (replaced the old HtlcState / HtlcStatus-enum). An HTLC is single-output — one recipient, one amount; a multi-recipient lock is several Htlcs carried by one transaction.
| Field | Type | Description |
|---|---|---|
htlc_id | string | Chain-native id — EVM: 32-byte keccak commitment (hex); Bitcoin: "txid:vout" |
asset_id | string | Locked asset's canonical id; the zero address for the native asset |
recipient | string | Claim key/address funds release to on claim |
amount | DecimalString | Locked amount, in the asset's display unit (e.g. BTC, ETH) |
payment_hash | bytes | 32-byte SHA-256 hashlock |
refund_address | string | Refund/sender key the timeout branch pays |
expiry | Timelock | Absolute timelock after which the refund branch opens |
lock_txid | string | Id of the transaction that locked this HTLC |
lock_depth | LedgerDepth (optional) | Depth the lock confirmed at; unset while unconfirmed / in mempool |
status | HtlcStatus | Lifecycle: Locked / Claimed / Refunded |
is_final | bool | (2026-10-29) Whether the network has made status final, so that no reorg can undo it: the lock while Locked, the claim or the refund once Claimed or Refunded. A watched HTLC is sent once more, with this set, when the network makes it final |
Two migrations to note (2026-06-11): amounts are now in the asset's display unit (the node scales to base units by decimals), and timelocks are absolute (
Timelock— Unix-seconds / block-height / slot / …), not "N blocks from now". The lock RPCs taketimelock_unix_seconds, nottimelock_blocks.
HtlcFees
(2026-10-29) What each on-chain step of one HTLC costs, in the network's native asset (BTC, ETH, TRX), at the fee option asked for. Returned by EstimateHtlcFees.
| Field | Type | Description |
|---|---|---|
lock | DecimalString | Locking the HTLC: the transaction funding it from the node's wallet. On Bitcoin it depends on amount, which decides how many wallet coins the lock spends |
claim | DecimalString | Claiming it with its preimage, by its recipient. On Bitcoin the claim pays its fee out of the HTLC; an HTLC too small to pay it and keep its payout above dust is refused |
sponsored_claim | DecimalString | Claiming it on its recipient's behalf (CompleteSponsoredHtlcClaim): on a UTXO chain the recipient's zero-fee claim and the child the node pays it with, on an account chain the claim the node submits, priced as a payout to an account the chain has never seen |
refund | DecimalString | Refunding it once its timelock has passed |
HtlcStatus
A oneof of:
Locked {}— on-chain. Distinguish confirmed (presentHtlc.lock_depth) from unconfirmed (absent).Claimed { claim_txid, claim_depth?, preimage }— recipient claimed; the 32-bytepreimage(the swap secret) is revealed.Refunded { refund_txid, refund_depth? }— refunded to the sender after timelock expiry.
Timelock and LedgerDepth
Both are protocol-native { value: uint64, kind: enum } pairs — kind fixes how value is read, so one shape spans every chain:
TimelockKind:UNIX_TIMESTAMP·BLOCK_HEIGHT·SLOT·SLOT_EPOCH·CHECKPOINT·ROUND·LEDGER_SEQUENCELedgerDepthKind:BLOCK_HEIGHT·SLOT·CHECKPOINT·ROUND·LEDGER_SEQUENCE
lock_type
Added 2026-07-11. A canonical protocol-defined script-kind token (e.g. Bitcoin "taproot" / "p2wsh") on the lock-building RPCs; empty selects the node's signer-derived default. On HtlcExpectation.lock_type it is a required-match pin — a receiving party sets it to the type its signer can settle, and any other type fails verification.
Route-level on-chain fields
On a matched order's route (SwapHop, from orderbook.proto):
sending_onchain(OnchainSendSettlement) — this hop's sending leg locks an HTLC the counterparty claims:counterparty_htlc_pubkey,timelock(TimelockSpec),confirmation_depth. Unset = channel.receiving_onchain(OnchainRecvSettlement) — the counterparty locks; this side verifies + claims:confirmation_depth. The counterparty's key / htlc_id / timelock arrive at runtime. (2026-11-17) In a swap whose secret the hub holds,timelock(TimelockSpec) is set here already: the timelock of the hub's lock toward you, fixed at the match.receiving_feeon the route's last hop also carries, for a swap with a leg settling on chain, what the swap charges for the hub's on-chain steps: the hub locks or pays youreceiving_amount − receiving_fee, and your swap trade records the charge asClientSwapTrade.onchain_fee.
On the route itself (SwapPath):
timing(SwapTiming) — set when the swap does not run on the venue's swap policy: when its on-chain locks need more time than the policy leaves, and (2026-11-17) for a swap whose secret the hub holds.swap_initial_expiry_secsandpayment_window_secsreplace the policy'sswap_initial_expiryandpayment_windowfor this swap, and (2026-11-17)swap_cltv_delta_secs, when set, the policy'sswap_cltv_deltafor your side of it: your receiving invoice's deadline lies that far past the deadline of what you pay — the invoice's expiry plus itsmin_final_cltv_expiry, or the timelock of your lock on chain — rounded up, never short of it. A receive minted on the policy's step where the swap names its own is refused, and the swap is cancelled without a strike. Before you send your receive, and again before you pay, check that the hub's last claim of your payment comes before your receive stops being claimable: seelate_claim_window_secsandpreimage_claim_margin_secsinGetNetworkInfo. Hydra App does both by itself. Unset = the policy's.prepay_amount,prepay_currencyandprepay_rail— (2026-11-17) the prepay a swap asks of you before the hub locks on chain toward you. See A prepay before the hub locks toward you.
A prepay before the hub locks toward you
(2026-11-17) In a swap whose secret the hub holds, the hub locks on chain toward a taker that receives on chain before the taker's own payment is held. Such a swap asks the taker a prepay first, named on its matched route (SwapPath):
prepay_amount(DecimalString), inprepay_currency, the currency you send: what the hub's lock toward you and the refund of that lock cost at the venue's fee estimates, and, for a prepay locked on chain, the hub's claim of it. A prepay locked on chain is never below the smallest output its chain relays plus the hub's claim of it: on Bitcoin, the dust limit of the lock's output and the fee of the hub's claim, so the hub can always claim it.prepay_rail(PrepayRail):PREPAY_RAIL_CHANNEL(1), a hold invoice of the hub's, paid over your channel;PREPAY_RAIL_ONCHAIN(2), an HTLC locked toward the hub.PREPAY_RAIL_UNSPECIFIED(0) when the swap asks none. Read a value you do not know asUNSPECIFIED:prepay_amountstill states the prepay.
The prepay is part of what you send, not on top of it: when the swap completes, the rest of your payment is your hop's sending_amount less prepay_amount. The hub's claim of a prepay locked on chain is one of the on-chain steps ClientSwapTrade.onchain_fee records. When the swap is cancelled:
- Kept by the hub when the swap is cancelled after its lock toward you reached its depth, unless the hub or the venue is at fault: your payment window lapsing (a lock of yours seen in time but short of its depth when the window ends counts as a lapse), or a decline of yours the venue finds no fault behind.
- Given back on any other cancel. Over a channel the hold invoice fails back, or, once the hub has taken the prepay, the venue owes it back and pays an invoice your node sends for exactly that amount. On chain your node refunds its lock at the lock's timelock.
Hydra App pays the prepay, and asks for one the venue owes back, by itself. Keep your node online, and the funds it pays from in place, until the swap ends.
Mainnet settles through channels only (see What differs from staging), so no swap there asks a prepay yet.
See also
- Swap API — opting a swap leg on-chain via
SwapRequest.settlement - Orderbook API → On-chain settlement — the
OrderSettlementfield reference - Events API → Subscribe HTLC Events — on-chain HTLC lifecycle stream
- Events API → On-chain HTLC Updates — swap milestones for on-chain legs
/proto/htlc.proto,/proto/preimage.proto,/proto/currency.proto— authoritative schemas