Integrate Lightning Network with Arkade using Submarine Swaps
Arkade provides seamless integration with the Lightning Network through Boltz submarine swaps, allowing users to move funds between Arkade and Lightning channels.
The BoltzSwapProvider library extends Arkade’s functionality by enabling:
Lightning to Arkade swaps - Receive funds from Lightning payments into your Arkade wallet
Arkade to Lightning swaps - Send funds from your Arkade wallet to Lightning invoices
This integration is built on top of the Boltz submarine swap protocol, providing a reliable and secure way to bridge the gap between Arkade and the Lightning Network.
By default this library doesn’t store pending swaps.If you need it you must initialize a storageProvider:
Copy
Ask AI
const storageProvider = StorageProvider.create({ storagePath: './storage.json' });const arkadeLightning = new ArkadeLightning({ wallet, swapProvider, storageProvider,});// you now are able to use the following methodsconst pendingPaymentsToLightning = arkadeLightning.getPendingSubmarineSwaps();const pendingPaymentsFromLightning = arkadeLightning.getPendingReverseSwaps();
To receive a Lightning payment into your Arkade wallet:
Copy
Ask AI
// Create a Lightning invoice that will deposit funds to your Arkade walletconst result = await arkadeLightning.createLightningInvoice({ amount: 50000, // 50,000 sats description: 'Payment to my Arkade wallet',});console.log('Receive amount:', result.amount);console.log('Expiry (seconds):', result.expiry);console.log('Lightning Invoice:', result.invoice);console.log('Payment Hash:', result.paymentHash);console.log('Pending swap', result.pendingSwap);console.log('Preimage', result.preimage);// The invoice can now be shared with the payer// When paid, funds will appear in your Arkade wallet
You must monitor the status of incoming Lightning payments.
It will automatically claim the payment when it’s available.
Copy
Ask AI
// Monitor the payment, it will resolve when the payment is receivedconst receivalResult = await arkadeLightning.waitAndClaim(result.pendingSwap);console.log('Receival successful!');console.log('Transaction ID:', receivalResult.txid);