Send & Receive on Lightning
Learn how to send and receive Lightning Network payments with your Spark wallet
Prerequisites
- A funded Spark wallet
- Basic understanding of Lightning Network invoices
- A counterparty with a Lightning-enabled wallet
Understanding Lightning Invoices
A Lightning invoice (also called a payment request) is a specially formatted string that contains all the information needed to make a Lightning Network payment:
- Amount: How many satoshis to send (can be optional)
- Destination: The recipient’s node public key
- Payment Hash: A unique identifier for the payment
- Description: Optional memo describing the payment
- Expiry: How long the invoice is valid for (default 24 hours)
Lightning invoices start with “ln” followed by the network identifier (bc for mainnet, bcrt for Regtest) and typically look like this:
lnbc1...
Mainnet invoice Example:
lnbc2500n1pj0ytfcpp5qqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqdx40shp5jqp3qymd6qgpy99ppk0jqjzylqg5t7fhqhpl6s4kxmqgmrn59w5k0z0cqqqqqqzqqqqq9qsqqqqqq9qqqqqqgq9qsqxl9l55y5cwa9s2h8nvdh4h7h43tcwjdcysf7v0fprz5uh6vshs4n0tvhgzz2xgcqpg8yqv7
Regtest invoice Example:
lnbcrt2500n1pj0ytfcpp5qqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqdx40shp5jqp3qymd6qgpy99ppk0jqjzylqg5t7fhqhpl6s4kxmqgmrn59w5k0z0cqqqqqqzqqqqq9qsqqqqqq9qqqqqqgq9qsqxl9l55y5cwa9s2h8nvdh4h7h43tcwjdcysf7v0fprz5uh6vshs4n0tvhgzz2xgcqpg8yqv7
Receiving Lightning Payments
We do not support Zero amount invoices. But those are coming soon! To receive a payment, generate a lightning invoice:
Sending Lightning Payments
To send a payment, you’ll need a Lightning invoice from the recipient:
Claiming Received Payments:
Once payment is done, Run getBalance()
with the forceRefetch
option to claim the payment and view the balance.
The getBalance()
method returns a Promise resolving to an object containing:
balance
: Abigint
representing the total amount in satoshistokenBalances
: A Map of token balances, where each entry contains:balance
: Abigint
representing the token amount
Paying an invoice directly from regtest
You can do this using the Lightning Command Line tool in the spark repo. Below are the set up instructions:
You can pay invoices using the Lightning Command Line tool in the spark repo. Below are the set up instructions:
Git clone the repo:
Go to the tools folder:
Install dependencies:
Verify rust is installed:
Run the Tool:
The first time you run the tool it will download additional dependencies. and then will process the lightning invoice payment. Second time you run it, it will process the payment faster.
Best Practices
- Always verify invoice amounts before paying
- In order to analyze invoice data, you can use the bolt11 library
- Keep track of payment hashes for reference
- Set appropriate expiry times for invoices
- Monitor payment status for confirmation
- Claim pending transfers after receiving payments by running
getBalance(true)
Next Steps
Now that you can send and receive Lightning payments, you might want to:
Need Help?
- Check our FAQ
- Review the API Reference
- Follow our Testing Guide
- Check our Code Samples