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. This integration leverages Hash Time-Locked Contracts (HTLCs) to ensure trustless and secure cross-chain atomic swaps.
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.
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({ amountSats: 50000, // 50,000 sats description: 'Payment to my Arkade wallet'});console.log('Lightning Invoice:', result.invoice);console.log('Payment Hash:', result.paymentHash);console.log('Expiry (seconds):', result.expirySeconds);// The invoice can now be shared with the payer// When paid, funds will appear in your Arkade wallet
You can monitor the status of incoming Lightning payments:
Copy
Ask AI
// Monitor the payment by payment hashconst subscription = arkadeLightning.monitorIncomingPayment(result.paymentHash);subscription.on('pending', () => { console.log('Payment detected but not yet confirmed');});subscription.on('confirmed', (txDetails) => { console.log('Payment confirmed!'); console.log('Transaction ID:', txDetails.txid); console.log('Amount received:', txDetails.amountSats, 'sats'); // Update your UI or notify the user updateBalanceDisplay();});subscription.on('failed', (error) => { console.error('Payment failed:', error.message);});// Don't forget to clean up when donesubscription.unsubscribe();