Skip to main content
Your user has funds on chain and wants to pay a Lightning invoice. This is a submarine swap.

How it works

Your app locks the funds on chain. The maker pays the invoice, which reveals its preimage, and only then can it claim your lockup. If the maker never pays, your app refunds the lockup. In the normal case your app only funds the lockup: it builds no transaction.

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.

Pay an invoice

1

Get a fixed-amount invoice

Use a BOLT11 invoice with an amount. For a Lightning address or an LNURL-pay link, resolve it first:
2

Create the swap

The SDK checks the maker’s answer against your refund key before it returns. Save the record before you fund.
3

Fund the lockup

Send exactly swap.expectedAmount to swap.address in one transaction from your wallet.
4

Wait for the payment

The swap reaches invoice.paid, then transaction.claimed. You are done.

If something goes wrong

If the swap reaches invoice.failedToPay, transaction.lockupFailed, or swap.expired, refund the lockup:
If the maker co-signs, the refund goes through immediately. If it does not, the refund is valid once the chain reaches the swap’s timeoutBlockHeight. See Claims and refunds.

Paying from other assets