Fiber LogoFiber Docs
Conditional payments20 minute tutorial

Build a Conditional Payment with a Hold Invoice

Pause an Invoice payment at the receiver, inspect its pending state, then explicitly settle or cancel it.

Hold InvoiceSettleCancel
1 Separate hash from preimage

Create an Invoice that cannot settle automatically

Node C generates the preimage locally, publishes only its SHA-256 hash in the Invoice, and keeps the preimage outside the node until a business condition is satisfied. The Invoice explicitly sets hash_algorithm: 'sha256' so settlement validates the preimage with the same algorithm.

lib/hold-invoice.ts · lines 7–18
2 Submit the payment

Prepare liquidity and supply the final hop

A newly funded receiver channel starts with its balance on Receiver C's side. Receiver C first sends a small Testnet payment to Bottle, moving 5 CKB to the remote side. Payer A then submits the Invoice with a private last-hop hint for Bottle → C.

Channel Ready is not Payment Ready

The Live Demo checks both channel liquidity and peer connections. Its last-hop hint removes the need to wait for the receiver channel to propagate through public gossip.

lib/payment.ts · lines 3–25
3 Observe the hold

Poll both sides without blocking the UI

Node C progresses from Open to Received, while Node A stays Inflight. This is the decision window.

lib/payment.ts · lines 27–32
4 Decide

Settle with the preimage or cancel

Settle releases the secret and completes the payment atomically. Cancel rejects the held Invoice and releases its pending liquidity.

lib/hold-invoice.ts · lines 19–25
5 Wire React

Expose the pending state as an explicit action

The interface enables Settle and Cancel only after the receiver reports Received, preventing an accidental early decision.

app/hold/page.tsx · lines 4–23