XSN Lightning Swaps (Testnet) Guide
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) Testnet. I 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 help with the testing of this technology then please proceed and let us know any issues or bugs you come across.
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, 2GB RAM, and 1 CPU. You will only use this server is only temporary, so I recommend one that you pay for by the hour.
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) 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.
Step 1) We now need to apply the following — as you are logged in as a superuser, the below will ask you to confirm your password to complete the command:
sudo apt install ufw python virtualenv git unzip pv golang-go
Installing the Testnet Wallets — Litecoin
We are first going to install the Litecoin wallet and put it into Testnet mode.
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
#=========
testnet=1
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 Testnet, input the following command:
~/.litecoin/litecoind
Step 5) You can check it is sync’ing with the following:
~/.litecoin/litecoin-cli getblockchaininfo
Installing the Testnet Wallets — XSN
We are now going to install the XSN wallet and put it into Testnet mode.
Step 1) Please copy and paste each command separately:
mkdir ~/.xsncore/wget https://github.com/X9Developers/lnd/raw/master/wallets/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
testnet=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 Testnet, input the following command:
~/.xsncore/xsnd
Step 5) You can check it is sync’ing with the following:
~/.xsncore/xsn-cli getblockchaininfo
Step 6) Add nodes to ensure the XSN Wallet syncs to the Testnet — copy and paste each line:
~/.xsncore/xsn-cli addnode 107.21.133.151 onetry~/.xsncore/xsn-cli addnode ec2–34–228–111–185.compute-1.amazonaws.com onetry~/.xsncore/xsn-cli addnode ec2–54–158–4–115.compute-1.amazonaws.com onetry~/.xsncore/xsn-cli addnode 34.228.111.185 onetry
Step 7) Wait for both the Litecoin and XSN wallets to sync to the chain, this will take around 15 to 30 minutes.
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/local/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/lndwget https://github.com/X9Developers/swap-resolver/releases/download/v1.0.0/lnd_xsncdsudo chmod 777 ~/lnd/ln*
Editing the start.bash files — Number 1
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 --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=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
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=localhost:10013 --restlisten=8003 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.testnet --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
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 --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=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
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=localhost:20013 --restlisten=9003 --datadir=data --logdir=logs --nobootstrap --no-macaroons --xsncoin.active --xsncoin.testnet --xsncoin.node=xsnd --xsnd.rpcuser=XXX --xsnd.rpcpass=XXX --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 prolfe.
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 testnet --rpcserver=localhost:10003 --no-macaroons'
alias xa-lnd-ltc='~/lnd/lncli --network testnet --rpcserver=localhost:10001 --no-macaroons'
alias xb-lnd-xsn='~/lnd/lncli --network testnet --rpcserver=localhost:20003 --no-macaroons'
alias xb-lnd-ltc='~/lnd/lncli --network testnet --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 commands individually:
source ~/.profilesudo chmod 777 ~/lnd/lnd sudo chmod 777 ~/lnd/lnd_xsn sudo chmod 777 ~/lnd/lncli
Getting your Exchanges Ready for Lightning Network Payment Tests
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. Ultimately, you will have 4 terminals open for Exchange A and 4 for Exchange B, and one extra one which acts as the binder.
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 get some Testnet funds for our wallets. 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:
XSN — Copy and paste the following then make note of the address:
xa-lnd-xsn newaddress np2wkh
LTC — Copy and paste the following then make note of the address:
xa-lnd-ltc newaddress np2wkh
Step 3) You have the address, and now you need the funds so do the following to get your XSNT and LTCT:
For XSN: Ask in the Discord #Lightning-network channel for some XSNt (testnet XSN) to test with and await confirmation it has been sent.
For LTC: Go to http://testnet.litecointools.com/ to get some LTCt (testnet LTC).
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 — the Binding Node.
Step 1) Open an additional Terminal of your VPS and copy and paste each line individual into the terminal:
XB_XSN_PUBKEY=`xb-lnd-xsn getinfo|grep identity_pubkey|cut -d '"' -f 4`xa-lnd-xsn connect $XB_XSN_PUBKEY@127.0.0.1:20013
Note: After inputting the above, each command output displayed will be similar to is {}, which is fine:
Step 2) Go to Exchange B, terminal 4 and confirm it remains synced to the chain with the following:
xb-lnd-xsn getinfo
If it is no longer synced —go to exchange B, Terminal 1 & 3, and do Ctrl & C, then use the up arrow and repeat the last command used in each terminal.
Step 3) Now copy and paste the following lines individually, into the same terminal as step 1:
XB_LTC_PUBKEY=`xb-lnd-ltc getinfo|grep identity_pubkey|cut -d '"' -f 4`xa-lnd-ltc connect $XB_LTC_PUBKEY@127.0.0.1:20011
Note: After inputting the above, each command output displayed will be similar to is {}, which is fine.
Step 4) Go to Exchange B, terminal 4 and confirm it remains synced to the chain with the following:
xb-lnd-ltc getinfo
If it is no longer synced — go to exchange B, Terminal 2 & 3, Ctrl & C, and do Ctrl & C, then use the up arrow and repeat the last command used in each terminal.
Step 5) Copy and paste the following lines individually, into the same terminal:
xa-lnd-xsn listpeersxa-lnd-ltc listpeers
We are now ready to set up payment channels.
Making a Lightning Network Payment
For these steps, we are using the Binding Node used in the previous step.
Step 1) For this step, Exchange A opens a xsn payment channel to Exchange B and pushes over 0.1 XSN at the same time. Copy and paste the following command:
xa-lnd-xsn openchannel --node_key=$XB_XSN_PUBKEY --local_amt=16000000 --push_amt=1000000 --sat_per_byte=1000
Step 2) We now need wait until the payment is confirmed (which could take a while; as it is testnet…), the pending channels can be seen with the pending channels command:
xa-lnd-xsn pendingchannels
Step 3) Once the channel is opened, Exchange A lists the payment channel with the following:
xa-lnd-xsn listchannels
Step 4) For this step, Exchange A opens a Litecoin payment channel to Exchange B and pushes over 0.05 LTC. Copy and paste the following command:
xa-lnd-ltc openchannel --node_key=$XB_LTC_PUBKEY --local_amt=10000000 --push_amt=5000000 --sat_per_byte=1000
Step 5) We need wait until the payment is confirmed (which could take a while; as mentioned before), the pending channels can be seen with the pending channels command:
xb-lnd-ltc pendingchannels
Step 6) Once confirmed, Exchange B lists the litecoin payment channel with the following:
xb-lnd-ltc 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
Step 2) Performing the Swap. In our example, Exchange A is willing to sell 200 satoshi (0.000002 XSN) for 10000 litoshi (0.0001 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:7001 takeorder --order_id=123 --maker_amount 200 --maker_coin XSN --taker_amount 10000 --taker_coin=LTC
After inputting the above command successfully, you should get the following confirmation:
You have now completed your first ever Lightning Swap!!!
I hope you have enjoyed this guide, and if you are ready for the real thing, we have tested this on Mainnet (live wallets) and confirms it works successfully.
If you have any questions or issues, remember to join the Stakenet Discord — https://discord.gg/MJc2x6f and we will be happy to help.