I want to develop Exchange where people would use my service to make payments using lightning network
I configured the LND node and created a wallet.
To implement this I would like to allow users to create addresses, and then to send money from one address to another (under same wallet) Moreover, If they wanted to withdraw money to random simple-bitcoin address (like 1BzVLSNcwznjoynyuFgMXwaGeevycLgDEN)
Therefore the very general question is: Is it possible?
The questions are:
Assume I created address#1 and address#2 under same wallet. How to transfer funds? Should I open a channel to do that?
Is it possible to send funds from address in lightning network to simple bitcoin address?
Are there any ways to choose sender address (in case users created thousands different addresses and user wants to send satoshis on behalf of himself)
- Assume I created address#1 and address#2 under same wallet. How to transfer funds? Should I open a channel to do that?
You seem to confuse bitcoin addresses and lightning network ids. If you have a lightning node you have a
node pubkey (called the
node_id). Of course there is a corresponding private key / secret. From this you can derive bitcoin addresses in your bitcoin wallet that is attached to the lightning node. Those addresses are used to fund your node or to claim funds from channels that for some reason hit the chain.
- Is it possible to send funds from address in lightning network to simple bitcoin address?
As from the first part of the answer. once the channels hit the chain they are in the bitcon network and can be send to any other bitcoin address. There are
exchange-services that allow and atomic on/off-chain swap. means you pay in invoice on lightning so that onchain bitcoin arrive at some address and vice versa.
- Are there any ways to choose sender address (in case users created thousands different addresses and user wants to send satoshis on behalf of himself)
If I understand your question correctly I would say it is possible. In the current setting people who offer a custodial wallet service seem to sign all invoices with the node ID of the lightningnode that is powering the custodial wallet. There speaks nothing against giving every user their own secrete and their own node id / bitcoin keys. You could even have virtual payment channels between the exchanges lightning network node that you maintain an run and between the "virtual" nodes of your customers which are basically private and suggest in the routing hints of the invoice to use the lightning node of your service. In order to do these kinds of tricks you might want to switch to c-lightning as with their plugin infrastructure have an API that allow easier customization for such features.
Bitcoin has addresses but there is no such thing as a Lightning "address" where you send the Lightning funds. A Lightning channel is opened by sending funds to a 2-of-2 multisignature Bitcoin address. From that point onwards invoices are sent back and forth using the Lightning protocol with balances updated as users agree to pay the invoices.
To receive your Bitcoin onchain and effectively leave the Lightning Network you close the channel and send Bitcoin from the 2-of-2 multisignature Bitcoin address to a Bitcoin address that is solely controlled by you.
You can run multiple Lightning nodes and send funds from any of those nodes that can afford to transfer the funds. When the receiver requests a Lightning payment they send an invoice that can be paid by any Lightning node. There is no restriction on where those funds should come from.