Skip to main content
Your user pays over Lightning and wants the funds on chain. This is a reverse swap.

How it works

Your app creates a secret and pays a hold invoice locked to it. The maker then locks the funds on chain to the same secret. Your app claims them, which reveals the secret and lets the maker settle your payment. Until your app claims, the Lightning payment is held, not settled. If the maker never locks, the payment is released back.

Setup

The code on this page assumes this setup. It connects to the signet maker and loads your swap mnemonic. See Installation and Keys and recovery if you have neither yet.

Receive funds

1

Create the swap

The SDK checks that the invoice is locked to your secret and that the lockup is claimable with your key.
2

Pay the invoice

Pay swap.invoice from any Lightning wallet. Check your payout address first: the claim is the first step that would reject a wrong-network address, and by then the invoice is paid.
3

Wait for the maker's lockup

The swap reaches transaction.mempool, then transaction.confirmed.
4

Claim

The swap ends in invoice.settled.

If something goes wrong

  • The maker never locks, or its lockup fails (transaction.failed, transaction.refunded): your Lightning payment is released automatically. Nothing to do.
  • Your app was offline: claim as soon as it comes back. A claim must confirm before the swap’s timeoutBlockHeight. claimReverseSwap checks the remaining margin and your chain evidence before revealing the secret; see Claims and refunds.
  • The broadcast response was lost: rebroadcast the saved transaction. Never sign a second claim.

Receiving other assets