LN Swap: How to be a swap provider?
LN Swap is a simple swap service that allows you to exchange funds (lightning <-> onchain) in a very simple and fast way, the software can be self-hosted so you can provide this service to other people in exchange for a small service fee, you can use this tool to capitalize your on-chain funds that are stalled today. But like everything in life there is risk, you can lose your funds due to a software bug or a block roll-back on the bitcoin mainchain, or even a failure in the LND.
Used technology stack
In order not to reinvent the wheel, we use solid technologies and resources that already exist in the LND and Bitcoin Core node, such as address generation, rate estimation etc... For the construction of the API I used a library written in Python called FastAPI, and to save data in Cache we use Redis with an expiration time, and a simple JSON database called Tinydb to save the data as soon as it is available, transaction is settled.
> This software is in development, do not use it in production.
How to install the back-end?
To install the software you must first download the code that is available on github:
git clone https://github.com/GrayFinance/ln-swap
Then create a virtual environment and install the necessary dependencies:
cd ln-swap
python3 -m virtualenv venv
source venv/bin/activate
pip3 install -r requirements.txt
Configuring the back-end.
Edit the .env file with your LND & Bitcoin Core node information.
# cat ~/.bitcoin/bitcoin.conf
# If the configuration file does not have the following
# configured parameters (rpcauth=username:password) add to
# file save and restart your Bitcoin node.
BTC_HOST = "http://127.0.0.1:8332"
BTC_USER = "username"
BTC_PASS = "password"
LND_HOST = "https://127.0.0.1:8080"
# Use the command to get the Admin macaroon encoded in HEX:
# xxd -ps -u -c 1000 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
LND_MACAROON = "0201036c6e6402f801030a105c33ad5698cd63fb1aea35457139e6d41201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e6572617465120472656164000006207700ab421f056fa7e73ec174a51452f0a93b3de5402359dd81929473af19b139"
LND_CERTIFICATE = "/home/node/.lnd/tls.cert" # echo ~/.lnd/tls.cert
# Configure the fees and the minimum amount for
# swap using these parameters.
LOOP_MIN_BTC = 0.00010000
SERVICE_FEE_RATE = 1 # (1% of fee service)
SERVICE_MIN_FEE_RATE = 0.00000500 # (If the percentage value is not greater than > 500 sats it will use this value as a fee.)
# If you don't have an instance of redis on your machine,
# you can use the command: docker run -p 6379:6379 -d redis redis-server --requirepass password
REDIS_PASS = "password"
Run the software using:
python3 __main__.py
How to install the front-end?
To install the front-end, just download the code with the command below, install the dependencies and run.
git clone https://github.com/GrayFinance/ln-swap-ui
cd ln-swap-ui
npm i
npm run dev
Final statements.
Observer that I made this project in a few days with technologies already available and working, anyone is welcome to contribute with the project and be able to use it as they see fit, if you want to send me a message, contact me via Twitter: