Lightning Swap guide (Stakenet dx mainchain)
By: Stakenet Team
Tags: Technology, Technical Documentation, Xsn, Stakenet, Bitcoin

Performing a Lightning Swap (Lightning Cross-Chain Swap)

We are on our final stage now, performing the actual swap.

Step 1) Checking the balance before the swap- Use the Binding Terminal from the previous step. Let’s check the XSN and LTC channel balances on Exchange A and B before we execute the swap.

In the outputs below, local_balance is the balance on Exchange A’s side of the channel and remote_balance on Exchange B’s side. Copy and paste the following commands individually:

xa-lnd-xsn listchannels xa-lnd-ltc listchannels

Exchange B will execute the following steps 2 to 2.2.

Step 2) Performing the Swap. In our example, Exchange A is willing to sell 25,000,000,000 stakoshi (250 XSN) for 10,000,000 litoshi (0.1 LTC).

The command is executed against the swap-resolver which controls the lnd’s. Copy and paste the following command:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/cmd/resolver-cli/

Step 2.1) Copy and Paste the following command:

sudo chmod 777 ./resolver-cli

Step 2.2) Copy and Paste the following command:

./resolver-cli --rpcserver localhost:7002 takeorder --order_id=123 --maker_amount 25000000000 --maker_coin XSN --taker_amount 10000000 --taker_coin LTC

After inputting the above command successfully, you should get the following confirmation:

You have now completed your first ever Lightning Swap with another person, with live wallets synced to the Mainnet!

In order to complete the swap and send the funds to the wallets, you will need to do the following:

Step 1) Copy and paste the following:

xa-lnd-ltc listchannels

This will return something similar to the following:

Step 2) from here we need “channel_point”: as in the above example, it is:

“c9ad8005acac992cd7b4400876af661f9267406340d559b9cbf8b2c8e95191ed:1”,

This contains two values: first is funding_txid and second is output_index.

Step 3) In order to close the channel and receive closing transaction, input the following command and input the above information from Step 2, in the <XX> fields.

xa-lnd-ltc closechannel --funding_txid=<funding_txid> --output_index=<output_index>

After 1 block will be generated balance will be back to your actual wallet.

Repeat the above Step 1 to 3, using the XSN command in step 1 instead:

xa-lnd-xsn listchannels xa-lnd-xsn closechannel --funding_txid=<funding_txid> --output_index=<output_index>

Step 4) In order to return the coins to your local wallet, input the following and amend the information accordingly-

Note: you must use a legacy LTC receiving address for it to send LTC and for both XSN & LTC, you must reduce the balance accordingly to account for network fees:

Exchange A

xa-lnd-ltc sendcoins --addr=<input ltc wallet address> --amt=<input coin amount> xa-lnd-xsn sendcoins --addr=<input xsn wallet address> --amt=<input coin amount>

Exchange B

xb-lnd-ltc sendcoins --addr=<input ltc wallet address> --amt=<input coin amount> xb-lnd-xsn sendcoins --addr=<input xsn wallet address> --amt=<input coin amount>

I hope you have enjoyed this guide, and are ready for the one-click solution we will be brining out shortly!

Either you want to claim your Swap bounty rewards or have any questions or issues, remember to join the Stakenet Discord — https://discord.gg/MJc2x6f and we will be happy to help.