Bitcoin lightning has been enabled for some time and has more than two thousand nodes.
A BTC user who wants to use lightning applications like Satoshi’s Place need to be a participant of the lightning network that requires the user to setup a BTC full node and run a lightning daemon. For non-BTC users, they have to convert their coins into BTC, setup a BTC full node and run a lightning daemon. It would be very convenient if there is a swap service that can take their on-chain coins and pay their lightning invoice.
Submarine Swaps are an atomic on-chain to off-chain swap service created by Alex Bosworth. It receives your on-chain BTC and pays for your off-chain BTC lightning invoice. It’s an atomic swap which means if your invoice is not paid within a specified time period you can get back the on-chain BTC that you sent.
You can try the on-chain tBTC to off-chain tBTC swap at https://submarineswaps.org/. The atomic swaps rely on a script contract that is similar to the following:
The “paymentHash” is the hash of the preimage and is presented in the lightning invoice. The preimage will be revealed to the payer of the lightning invoice after payment. The swap service provider pays the invoice to get the preimage and use it as a proof of payment to claim the fund at swap address. If the invoice is not paid the swap service provider will not have the preimage and cannot move the fund at swap address. After a specified time, the user can move the fund at swap address back to the refund address which is controlled by the user.
Cross-chain submarine swap
Same chain swap is good but cross-chain swap is even better. I forked the submarine swaps project and make it able to swap on-chain LTC to off-chain BTC. Now users can pay BTC lightning invoice with on-chain LTC.
Here is how the cross-chain swap works:
- A user presents a valid BTC lightning invoice and on-chain LTC refund address (if not using “refund paper wallet”).
- Swap service provider creates the contract(as discussed above) and gives a P2SH LTC address(a.k.a. swap address) that encoded the hash of the contract script.
- The user pays the amount specified by swap service provide to the swap address.
- After funds transfer to the swap address are confirmed, swap service provider pays the LN invoice and then claim the funds at swap address.
- If the lightning invoice is not paid, the user moves the fund at swap address to the refund address that is controlled by the user.