Lightning Swap guide (Stakenet dx mainchain)

Hydranet Team
Stakenet
Published in
18 min readOct 27, 2018

--

Hello and welcome to a Stakenet Tutorial Guide.

In this guide we will explain how to conduct your first Lightning Swap on the XSN and Litecoin (LTC) Mainnet, with another person.

We have tried to make this guide as simple as possible and will mainly consist of copy and pasting commands however; we would advise that you have some working knowledge of using an Ubuntu VPS such as setting up a Masternode or TPoS server.

We will be implementing a one-click solution within our upcoming wallet so the average user is able to use it without the below steps as it will be implemented and automated by the wallet.

If you are a little tech savvy and want to test out this feature then please get involved and join our Discord on the link at the end of this article.

Within this guide, you will be fufilling the role of Exchange A.

Exchange B steps are for reference only should you want someone other than the XSN Team, to conduct a swap with you.

As always, with the testing of new technology, if you find any issues or bugs then please let us know.

Requirements for testing the Lightning Swap:

First things first, to be able to run the test, you will require the following:

  • A new VPS that has a 40GB SSD/HDD, 2GB RAM, and 1 CPU. You will only use this server temporarily, so I recommend one that you pay for by the hour.
  • 0.12 LTC (Exchange A- this will be you in this guide)
  • A bit of time and coffee as LTC chain takes circa. 4 hours at least to sync

Getting Started — Preparing your VPS

First step is to log into your VPS and do the following:

Step 1) Add a new user which you will use to login — Change “username” to the desired name but only use lowercase:

adduser username

Step 2) Next you want to make your new user a super user. Input the following command and replace username with the one you created in the previous step:

usermod -aG sudo username

Step 3) Next you want to get updates and apply them to your server:

apt update && apt full-upgrade -y

Step 4) Copy and paste the following lines in order to get your firewall started:

apt install ufw python virtualenv git unzip pvufw allow ssh/tcpufw limit ssh/tcpufw logging onufw enable

Step 5) As with above, copy and paste each line separately.

fallocate -l 4G /swapfilechmod 600 /swapfilemkswap /swapfileswapon /swapfilenano /etc/fstab

Step 6) The nano command will move to a different screen. Once that is open, use your arrow keys to navigate to the bottom and paste the below line.

/swapfile none swap sw 0 0

Note: You must make sure that the above spaces between each word & number is separated by using tab on your keyboard, which is indicated by the red lines in the image below:

Once inputted, go Ctrl + X, followed by “Y”, and then Enter.

Step 7) Once your server has finished applying the above updates, you will now need to reboot your server with the following:

reboot now

Logging in as your Superuser

Once your server has rebooted, you now need to login as the superuser you created earlier.

Installing the Wallets — Litecoin

We are first going to install the Litecoin wallet.

Step 1) Please copy and paste each command separately:

mkdir ~/.litecoin/wget https://download.litecoin.org/litecoin-0.16.3/linux/litecoin-0.16.3-x86_64-linux-gnu.tar.gztar xfvz litecoin-0.16.3-x86_64-linux-gnu.tar.gzcp litecoin-0.16.3/bin/litecoind ~/.litecoin/cp litecoin-0.16.3/bin/litecoin-cli ~/.litecoin/

Step 2) Now we need to edit the Litecoin.conf:

nano ~/.litecoin/litecoin.conf

Step 3) Add the following lines and edit the information in bold — please make note of your rpc user & password as you will need them later:

#=========
rpcallowip=127.0.0.1
rpcuser=RANDOMNAME
rpcpassword=RANDOMPASSWORD
#=========
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
#=========
listen=1
daemon=1
server=1
#=========

Step 4) To save the above file, you will need to go CTRL+X, then “Y” followed by ENTER.

Step 5) To start the Litecoin wallet so it can commence sync’ing to the Mainnet, input the following command:

~/.litecoin/litecoind

Step 5) You can check it is sync’ing with the following:

~/.litecoin/litecoin-cli getblockchaininfo

Installing the Wallets — XSN

We are now going to install the XSN wallet.

Step 1) Please copy and paste each command separately:

mkdir ~/.xsncore/wget https://github.com/X9Developers/XSN/releases/download/v1.0.16/xsn-1.0.16-x86_64-linux-gnu.tar.gztar xfvz xsn-1.0.16-x86_64-linux-gnu.tar.gzcp xsn-1.0.16/bin/xsnd ~/.xsncore/cp xsn-1.0.16/bin/xsn-cli ~/.xsncore/

Step 2) Now we need to edit the xsn.conf:

nano ~/.xsncore/xsn.conf

Step 3) Add the following lines and edit the information in bold — please make note of your rpc user & password as you will need them later:

#=========
rpcallowip=127.0.0.1
rpcuser=RANDOMNAME
rpcpassword=RANDOMPASSWORD
#=========
zmqpubrawblock=tcp://127.0.0.1:28444
zmqpubrawtx=tcp://127.0.0.1:28445
#=========
listen=1
server=1
daemon=1
#=========

Step 4) To save the above file, you will need to go CTRL+X, then “Y” followed by ENTER.

Step 5) To start the XSN wallet so it can commence sync’ing to the mainnet, input the following command:

~/.xsncore/xsnd

Step 5) You can check it is sync’ing with the following:

~/.xsncore/xsn-cli getblockchaininfo

Step 7) Wait for both the Litecoin and XSN wallets to sync to the chain, this will take around 15 to 30 minutes for XSN and a few hours for LTC.

Adding Go Paths for the VPS.

We now need to add some paths.

Step 1) Copy and paste the following:

nano ~/.bashrc

Step 2) Add the following lines to the end of the bashrc — use the downward arrow on your keyboard to navigate down very bottom:

#=========
# add Go paths
export GOPATH=$HOME/go
export PATH=/usr/bin/go/bin:$GOPATH/bin:$PATH
#=========

It will look like this:

Step 3) To save the above file, you will need to go CTRL+X, then “Y” followed by ENTER.

Step 4) Copy and paste the following:

source ~/.bashrc

Clone swap-resolver git

We now need to get the tools to prepare for the lightning swap.

Step 1) Copy and paste the following (It is one full line of text so copy it all):

git clone https://github.com/X9Developers/swap-resolver.git $GOPATH/src/github.com/ExchangeUnion/swap-resolver

Step 2) Copy and paste each of the following lines individually:

mkdir ~/lnd/cd ~/lnd/wget https://github.com/X9Developers/swap-resolver/releases/download/v1.0.0/lncliwget https://github.com/X9Developers/swap-resolver/releases/download/v1.0.0/lnd_ltcwget https://github.com/X9Developers/swap-resolver/releases/download/v1.0.0/lnd_xsncdsudo chmod 777 ~/lnd/ln*

Editing the start.bash files — Number 1 (Exchange A)

This section is a bit manual and I will break it up into four parts for each start.bash however; doing this is very necessary.

Step 1) Copy and paste the following (It is one full line of text so copy it all) and we need to edit the first start.bash for Litecoin:

nano ~/go/src/github.com/ExchangeUnion/swap-resolver/exchange-a/lnd/ltc/start.bash

Step 2) We need to edit the first start.bash for Litecoin, the first one is how it currently looks, and the second shows what you need to edit:

The original will be a long line of text like the below:

lnd --noseedbackup --rpclisten=localhost:10001 --listen=localhost:10011 --restlisten=8001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.testnet --litecoin.node=litecoind --litecoind.rpcuser=xu --litecoind.rpcpass=xu --debuglevel=debug --litecoind.zmqpubrawblock=tcp://127.0.0.1:28332 --litecoind.zmqpubrawtx=tcp://127.0.0.1:28333 --alias="Exchange A LTC on 10001/10011"

You will need to modify the information in bold:

~/lnd/lnd_ltc --noseedbackup --rpclisten=localhost:10001 --listen=0.0.0.0:10011 --restlisten=8001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.mainnet  --litecoin.node=litecoind --litecoind.rpcuser=HERE --litecoind.rpcpass=HERE --debuglevel=debug --litecoind.zmqpubrawblock=tcp://127.0.0.1:28332 --litecoind.zmqpubrawtx=tcp://127.0.0.1:28333 --alias="Exchange A LTC on 10001/10011"

Input the rpcuser name and password that you inputted into the litecoin.conf earlier.

Editing the start.bash files — Number 2 (Exchange A)

Step 1) Copy and paste the following (It is one full line of text so copy it all) and we need to edit the first start.bash for XSN:

nano ~/go/src/github.com/ExchangeUnion/swap-resolver/exchange-a/lnd/xsn/start.bash

Step 2) We need to edit the first start.bash for XSN, the first one is how it currently looks, and the second shows what you need to edit:

The original will be a long line of text like the below:

lnd --noseedbackup --rpclisten=localhost:10003 --listen=localhost:10013 --restlisten=8003 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.testnet --xsncoin.node=xsnd --xsnd.rpcuser=xu --xsnd.rpcpass=xu --xsnd.zmqpubrawblock=tcp://127.0.0.1:28444 --xsnd.zmqpubrawtx=tcp://127.0.0.1:28445 --debuglevel=debug --alias="Exchange A XSN on 10003/10013"

You will need to modify the information in bold

~/lnd/lnd_xsn --noseedbackup --rpclisten=localhost:10003 --listen=0.0.0.0:10013 --restlisten=8003 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.mainnet --xsncoin.node=xsnd --xsnd.rpcuser=HERE --xsnd.rpcpass=HERE --xsnd.zmqpubrawblock=tcp://127.0.0.1:28444 --xsnd.zmqpubrawtx=tcp://127.0.0.1:28445 --debuglevel=debug --alias="Exchange A XSN on 10003/10013"

Input the rpcuser name and password that you inputted into the xsn.conf earlier.

Editing the start.bash files — Number 3 (Exchange B)

Step 1) Copy and paste the following (It is one full line of text so copy it all) and we need to edit the first start.bash for Litecoin:

nano ~/go/src/github.com/ExchangeUnion/swap-resolver/exchange-b/lnd/ltc/start.bash

Step 2) We need to edit the second start.bash for Litecoin, the first one is how it currently looks, and the second shows what you need to edit:

The original will be a long line of text like the below:

lnd --noseedbackup --rpclisten=localhost:20001 --listen=localhost:20011 --restlisten=9001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.testnet --litecoin.node=litecoind --litecoind.rpcuser=xu --litecoind.rpcpass=xu --debuglevel=debug --litecoind.zmqpubrawblock=tcp://127.0.0.1:28332 --litecoind.zmqpubrawtx=tcp://127.0.0.1:28333 --alias="Exchange B LTC on 20001/20011"

You will need to modify the information in bold:

~/lnd/lnd_ltc --noseedbackup --rpclisten=localhost:20001 --listen=0.0.0.0:20011 --restlisten=9001 --datadir=data --logdir=logs --nobootstrap --no-macaroons --litecoin.active --litecoin.mainnet --litecoin.node=litecoind --litecoind.rpcuser=HERE --litecoind.rpcpass=HERE --debuglevel=debug --litecoind.zmqpubrawblock=tcp://127.0.0.1:28332 --litecoind.zmqpubrawtx=tcp://127.0.0.1:28333 --alias="Exchange B LTC on 20001/20011"

Input the rpcuser name and password that you inputted into the litecoin.conf earlier.

Editing the start.bash files — Number 4 (Exchange B)

Step 1) Copy and paste the following (It is one full line of text so copy it all) and we need to edit the first start.bash for XSN:

nano ~/go/src/github.com/ExchangeUnion/swap-resolver/exchange-b/lnd/xsn/start.bash

Step 2) We need to edit the second start.bash for XSN, the first one is how it currently looks, and the second shows what you need to edit:

The original will be a long line of text like the below:

lnd --noseedbackup --rpclisten=localhost:20003 --listen=localhost:20013 --restlisten=9003 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.testnet --xsncoin.node=xsnd --xsnd.rpcuser=xu --xsnd.rpcpass=xu --xsnd.zmqpubrawblock=tcp://127.0.0.1:28333 --xsnd.zmqpubrawtx=tcp://127.0.0.1:28332 --debuglevel=debug --alias="Exchange B XSN on 20003/20013"

You will need to modify the information in bold:

~/lnd/lnd_xsn --noseedbackup --rpclisten=localhost:20003 --listen=0.0.0.0:20013 --restlisten=9003 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.mainnet --xsncoin.node=xsnd --xsnd.rpcuser=HERE --xsnd.rpcpass=HERE --xsnd.zmqpubrawblock=tcp://127.0.0.1:28444 --xsnd.zmqpubrawtx=tcp://127.0.0.1:28445 --debuglevel=debug --alias="Exchange B XSN on 20003/20013"

Input the rpcuser name and password that you inputted into the xsn.conf earlier.

Editing the start.bash files — Resolver

In order for the swap to sucessfuly swap between two peers, you will need to edit the following:

If you are Exchange A in the Swap:

Step 1) Copy and paste the following (It is one full line of text so copy it all) and we need to edit the first start.bash for Litecoin:

nano $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-a/resolver/start.bash

Step 2) We need to edit the first start.bash for Litecoin, the first one is how it currently looks, and the second shows what you need to edit:

The original will be a long line of text like the below:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolvercase "$1" in
"btc_ltc")
./resolver --listen localhost:7001 --peer localhost:7002 --lnd-rpc-ltc localhost:10001 --lnd-rpc-btc localhost:10002
;;
"btc_xsn")
./resolver --listen localhost:7001 --peer localhost:7002 --lnd-rpc-btc localhost:10002 --lnd-rpc-xsn localhost:10003
;;
"ltc_xsn")
./resolver --listen localhost:7001 --peer localhost:7002 --lnd-rpc-ltc localhost:10001 --lnd-rpc-xsn localhost:10003
;;
*)
echo "Wrong argument passed, supported modes to swap are: btc_ltc, btc_xsn, ltc_xsn"

You will need to modify the information in bold:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolvercase "$1" in
"btc_ltc")
./resolver --listen localhost:7001 --peer localhost:7002 --lnd-rpc-ltc localhost:10001 --lnd-rpc-btc localhost:10002
;;
"btc_xsn")
./resolver --listen localhost:7001 --peer localhost:7002 --lnd-rpc-btc localhost:10002 --lnd-rpc-xsn localhost:10003
;;
"ltc_xsn")
./resolver --listen 0.0.0.0:7001 --peer ExchangeB_IP*:7002 --lnd-rpc-ltc localhost:10001 --lnd-rpc-xsn localhost:10003
;;
*)
echo "Wrong argument passed, supported modes to swap are: btc_ltc, btc_xsn, ltc_xsn"

*you will need to input exchange B’s Public IP here (their VPS IP).

If you are Exchange B in the Swap:

Step 1) Copy and paste the following (It is one full line of text so copy it all) and we need to edit the first start.bash for Litecoin:

nano $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-b/resolver/start.bash

Step 2) We need to edit the first start.bash for Litecoin, the first one is how it currently looks, and the second shows what you need to edit:

The original will be a long line of text like the below:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolvercase "$1" in
"btc_ltc")
./resolver --listen localhost:7002 --peer localhost:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-btc localhost:20002
;;
"btc_xsn")
./resolver --listen localhost:7002 --peer localhost:7001 --lnd-rpc-btc localhost:20002 --lnd-rpc-xsn localhost:20003
;;
"ltc_xsn")
./resolver --listen localhost:7002 --peer localhost:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-xsn localhost:20003
;;
*)
echo "Wrong argument passed, supported modes to swap are: btc_ltc, btc_xsn, ltc_xsn"

You will need to modify the information in bold:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolvercase "$1" in
"btc_ltc")
./resolver --listen localhost:7002 --peer localhost:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-btc localhost:20002
;;
"btc_xsn")
./resolver --listen localhost:7002 --peer localhost:7001 --lnd-rpc-btc localhost:20002 --lnd-rpc-xsn localhost:20003
;;
"ltc_xsn")
./resolver --listen 0.0.0.0:7002 --peer ExchangeA_IP*:7001 --lnd-rpc-ltc localhost:20001 --lnd-rpc-xsn localhost:20003
;;
*)
echo "Wrong argument passed, supported modes to swap are: btc_ltc, btc_xsn, ltc_xsn"

*you will need to input exchange A’s Public IP here (their VPS IP).

Editing the Firewall.

As we are going to be swapping with another peer, we need to open ports on your VPS to allow both peers to communicate to each other.

If you are Exchange A:

Step 1) Copy and paste the following to open the correct ports in your Firewall:

sudo ufw allow 10011/tcpsudo ufw allow 7001/tcpsudo ufw allow 10013/tcp

If you are Exchange B:

Step 1) Copy and paste the following to open the correct ports in your Firewall:

sudo ufw allow 20011/tcpsudo ufw allow 20013/tcpsudo ufw allow 7002/tcp

Editing the profile.

We need to add a few lines of text, though this step is very much copy and paste.

Step 1) Copy and paste the following:

nano ~/.profile

Step 2) Add the following lines to the end of the bashrc — use the downward arrow on your keyboard to navigate down very bottom.

#=========
#Adding lncli aliases
alias xa-lnd-xsn='~/lnd/lncli --network mainnet --rpcserver=localhost:10003 --no-macaroons'
alias xa-lnd-ltc='~/lnd/lncli --network mainnet --rpcserver=localhost:10001 --no-macaroons'
alias xb-lnd-xsn='~/lnd/lncli --network mainnet --rpcserver=localhost:20003 --no-macaroons'
alias xb-lnd-ltc='~/lnd/lncli --network mainnet --rpcserver=localhost:20001 --no-macaroons'
#=========

Step 3) To save the above file, you will need to go CTRL+X, then “Y” followed by ENTER.

Step 4) Copy and paste the following lines individually:

source ~/.profilesudo chmod 777 ~/lnd/lnd_ltcsudo chmod 777 ~/lnd/lnd_xsnsudo chmod 777 ~/lnd/lncli

Getting your Exchanges Ready for Lightning Network Swap

For the next steps, you are going to have to open multiple versions of your VPS terminal however; only open a new one when the steps says so.

Remember, if you are Exchange A in this swap, then only follow the steps for Exchange A, and likewise, if you are Exchange B, then only do the steps for Exchange B.

Ultimately, you will have 4 terminals open.

Exchange A

Terminal one — launching lnd-xsn:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-a/lnd/xsn/

Step 2) Copy and paste the following:

./start.bash

Terminal two — launching lnd-ltc:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-a/lnd/ltc/

Step 2) Copy and paste the following:

./start.bash

Terminal three — launching swap-resolver:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-a/resolver/

Step 2) Copy and paste the following:

./start.bash ltc_xsn

Terminal four — Sync checker:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following command to check if you have synced to the chain on the XSN wallet for Exchange A:

xa-lnd-xsn getinfo

We are waiting for it to say the following:

Step 2) Within the same terminal, we now want to check that Exchange A LTC wallet has synced. Copy and paste the following:

xa-lnd-ltc getinfo

We are waiting for it to say the following:

Please note: if the synced_to_chain takes a while to change to true, go back to terminal one and two, and go Ctrl + C, then use the Up arrow on your keyboard to select the last used command, and re-run that command. Once done, go back to your terminal four and check the sync status.

Exchange B

Terminal one — launching lnd-xsn:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-b/lnd/xsn/

Step 2) Copy and paste the following:

./start.bash

Terminal two — launching lnd-ltc:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-b/lnd/ltc/

Step 2) Copy and paste the following:

./start.bash

Terminal three — launching swap-resolver:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following:

cd $GOPATH/src/github.com/ExchangeUnion/swap-resolver/exchange-b/resolver/

Step 2) Copy and paste the following:

./start.bash ltc_xsn

Terminal four — Sync checker:

Step 1) Open a new terminal, log in as your Superuser and copy and paste the following command to check if you have synced to the chain on the XSN wallet for Exchange B:

xb-lnd-xsn getinfo

We are waiting for it to say the following:

Step 2) Within the same terminal, we now want to check that Exchange B LTC wallet has synced. Copy and paste the following:

xb-lnd-ltc getinfo

We are waiting for it to say the following:

Getting your Exchange Wallet Addresses

Make sure your exchanges are synced before proceeding!

For the next steps, we are going to check our wallet balances as they should be 0, generate a receiving address and then you will send your funds to your generated receiving addresses. We are going to use Exchange A terminal four, for the following (the terminal you checked for synced_to_chain).

Step 1) Input each of the following commands individually to check the wallet balance on the exchange:

xa-lnd-xsn walletbalancexa-lnd-ltc walletbalance

Step 2) Now we need to generate your exchange receiving addresses with the following:

Exchange A — Creating an LTC address: Copy and paste the following then make note of the address:

xa-lnd-ltc newaddress np2wkh

You have the address, and now you need to send the funds to them — remember, send 0.12 LTC to the right address you generated above.

Exchange B — Creating an XSN address: Copy and paste the following then make note of the address:

xb-lnd-xsn newaddress np2wkh

You have the address, and now you need to send the funds to them — remember, send XSN to the right address you generated above.

Once received and confirmed in your wallet (use step 1 to check), we are ready to commence Lightning Network Payment Tests.

Establishing Lightning Peer Connections

For the next steps, we are going to establish a connection between Exchange A and Exchange B.

If you are Exchange A (swapping LTC for XSN)

Step 1) In your fourth terminal, copy and paste the following line into the terminal:

xa-lnd-xsn getinfo

Step 2) You will need to copy your “identity_pubkey” and send to the peer for exchange B.

"identity_pubkey": "035fe862eb68a1fd2afd2a4366f1593982c9a3357527d4fd576d022dc2ced0468e",

Step 3) Exchange B, will need to send their LTC pubkey to you and you will need to input the following command:

XB_LTC_PUBKEY=INPUT_Exchange_B_pubkey_here

Step 4) Once the above has been done, you will need to input the following command and edit it to include the IP of exchange A:

xa-lnd-ltc connect $XB_LTC_PUBKEY@Exchange_B_IP:20011

If you are Exchange B (swapping XSN for LTC)

Step 1) In your fourth terminal, copy and paste the following line into the terminal:

xb-lnd-ltc getinfo

Step 2) You will need to copy your “identity_pubkey” and send to the peer for exchange A.

"identity_pubkey": "035fe862eb68a1fd2afd2a4366f1593982c9a3357527d4fd576d022dc2ced0468e",

Step 3) Exchange A, will need to send you their pubkey for XSN and you will need to input the following command:

XA_XSN_PUBKEY=INPUT_Exchange_A_pubkey_here

Step 4) Once the above has been done, you will need to input the following command and edit it to include the IP of exchange A:

xb-lnd-xsn connect $XA_XSN_PUBKEY@EXCHANGEA_IP:10013

Checking Exchanges are listening to each other:

Exchange A

Step 1) Copy and paste the following lines, into the same terminal and checm it has registered the information for Exchange B:

xa-lnd-ltc listpeersxa-lnd-xsn listpeers

Exchange B

Step 1) Copy and paste the following lines, into the same terminal and checm it has registered the information for Exchange A:

xb-lnd-ltc listpeersxb-lnd-xsn listpeers

We are now ready to set up payment channels.

Opening a Lightning Network Channel

For these steps, we are using the Binding Node used in the previous step.

Step 1) For this step, Exchange A opens a LTC payment channel of 0.11 LTC to Exchange B. Copy and paste the following command:

xa-lnd-ltc openchannel --node_key=$XB_LTC_PUBKEY --local_amt=11000000 --push_amt=0 --sat_per_byte=1000

Step 2) We now need wait until the payment is confirmed though the above command would have generated a transaction id you can track in the xsnexplorer.io, the pending channels can be seen with the pending channels command:

xa-lnd-ltc pendingchannels

Step 3) Once the channel is opened, Exchange A lists the payment channel with the following:

xa-lnd-ltc listchannels

Step 4) For this step, Exchange B opens an XSN payment channel to Exchange A for 260 XSN.

Exchange B — Copy and paste the following command:

xb-lnd-xsn openchannel --node_key=$XA_XSN_PUBKEY --local_amt=26000000000 --push_amt=0 --sat_per_byte=1000

Step 5) We need wait until the payment is confirmed although the above command will generate a transaction ID you can track in the XSN block explorer, the pending channels can be seen with the pending channels command:

xb-lnd-xsn pendingchannels

Step 6) Once confirmed, Exchange B lists the litecoin payment channel with the following:

xb-lnd-xsn listchannels

Once confirmed, you have done all Lightning Network checks and get to move onto the final stage, Lightning Swaps!

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 listchannelsxa-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 listchannelsxa-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.

--

--