Learn Center
How to Perform Bitcoin Swaps to Stacks on LNSwap

How to Perform Bitcoin Swaps to Stacks on LNSwap

How to swap BTC for STX using LNSwap? The LNSwap team gives a walkthrough.

LNSwap is a decentralized swap protocol that makes Bitcoin swaps for other tokens fast and easy. Unlike centralized exchanges (CEXs) and decentralized exchanges (DEXs), LNSwap uses atomic swaps for peer-to-peer transactions (P2P).

Don’t worry, we’ll get into the details and learn how to swap in this guide. For now, just remember that LNSwap allows you to easily swap assets between Bitcoin and digital assets on the Stacks layer.

How Does LNSwap Work?

LNSwap is a complex protocol, just like any blockchain technology — but we can explain the concept simply.

Imagine Alice wants to swap cryptocurrencies with Bob. Both Alice and Bob can place the digital assets they want to swap in a hashed time-locked contract (HTLC). Think of it like a vault.

After both parties have deposited their assets, the amount and type of currency gets confirmed by a smart contract. Only after this can they retrieve their swapped assets. When the vault is unlocked, Bob and Alice each take their exchanged crypto and enjoy the rest of their day.

Swaps on LNSwap are different from trades on CEXs and DEXs because they don’t require trust between Bob and Alice. They also don’t require trust in a third party. A P2P swap allows you to swap one cryptocurrency for another without an intermediary.

Centralized cryptocurrency exchanges have a large pool of assets that is held by a third party. This makes users vulnerable to that one, centralized point of failure. Even on a DEX, there's a risk of hacking or code failure. And although liquidity pools are decentralized, if a contract fails or is exploited, users can lose their funds.

Atomic Swaps and Submarine Swaps

Swaps made on LNSwap are called submarine swaps. These are a type of atomic swap that uses HTLCs to enforce the swap parameters between blockchains. The HTLC acts as a vault, locking the funds for both parties until the swap agreement is fulfilled.

Because an HTCL is time-locked, this also means there’s a deadline for the swap to be completed. If it’s not done in time, each user gets their original tokens returned.

LNSwap uses Lightning Network channels to make swaps. But a problem occurs because the Bitcoin blockchain and Lightning Network are not interoperable. On-chain Bitcoin addresses can’t send tokens to off-chain Lightning addresses. Submarine swaps solve this by allowing the LN channel a swap uses to be refilled. It does this by creating an on-chain Bitcoin transfer to the LN channel. You can read more about this process here.

Making a Bitcoin Swap from BTC to STX

Now let’s talk about how to make a Bitcoin swap using the LNSwap exchange platform.

The first thing you need is a crypto wallet. We’ll show this example with Hiro Wallet. Once you’ve created a wallet and added the wallet app extension to your browser, you’re ready to connect it to LNSwap. Go to the exchange.  

A prompt for Hiro Wallet users to download the Google Chrome extension

Connect Your Wallet

Use the “Connect Wallet” button and follow the prompts to connect your Hiro Wallet. You should also make sure to buy crypto and fund your wallet. You’ll need to have some STX in your wallet because after you swap BTC, there are withdrawal transaction fees.

Select Your Tokens and Amount

With your wallet connected, choose which tokens you want to swap and enter the amount you want to trade. There are options to swap Bitcoin (BTC), Stacks tokens (STX), and XUSD, which is a stable coin. You’ll be able to see the dollar exchange rate in the interface and amounts should update automatically as you change the swap amount. We’ll show a BTC swap in this example.

Exchanging BTC for STX through LNSwap via Hiro Wallet

Confirm Your Wallet Address

Next, confirm the address that your tokens will be sent to.

A sample Hiro Wallet address for the BTC to STX token swap

The Refund File

On this page, you have the chance to download a refund QR code. If the swap is not completed in time, you’ll be able to get your tokens back via the refund file. Make sure to keep this until the BTC swap is complete so you don’t lose your tokens.

An example of a Hiro Wallet refund file

Put Your Tokens in the Vault

The next step is to place your tokens in the HTLC. If you’re swapping BTC for STX, you’ll need to send the correct amount of BTC — from wherever you store your bitcoin — to the provided address. Once you’ve done this, the swap can be verified. This typically takes about 10 minutes.

Sending BTC tokens through Hiro Wallet

Claim Your Tokens

After the swap is confirmed, you can claim your tokens! When you click the button to claim, your Hiro Wallet will be opened.

A Hiro Wallet extension page allowing users to claim their STX

Confirm Your Claim

If everything looks good in the transaction summary, click confirm. On a final details page, you’ll be able to see all the information about your swap.

The final confirmation page detailing the BTC to STX swap

Final Swap Review

After you confirm your swap, it should take another few minutes and then you’re finished. If you need to use your refund code, you can do that here.

A page through the Hiro Wallet extension confirming that a swap is successful

Conclusion: The Benefits of Truly Trustless Crypto Exchanges

Using LNSwap for Bitcoin swaps is easy, but most importantly, it’s completely trustless and secure.

Blockchains or protocols that aren’t completely secure create huge risks for their users. Bitcoin is the oldest and most secure network for a reason. Protocol layers like LNSwap, Lightning Network, and Stacks make it easier to use the Bitcoin network without sacrificing true peer-to-peer, trustless transactions.

The more trustless technologies become easy and reliable to use, the more adoption they’ll get. That’s what LNSwap is doing. Using the security of Bitcoin and the speed of layer 2s like Lightning Network, crypto transactions can remain truly P2P.

Posted on: Sep 11, 2023

Updated on: Sep 11, 2023

This is some text inside of a div block.

Start swapping Bitcoin for Stacks

LNSwap is a non custodian crypto currency swap protocol that provides a fast, private way of swapping Bitcoin for Stacks and vice versa.