Available in SDK version 0.4.1+. Rollback feature and improved defaults in 0.4.2+.
How It Works
- Decode invoice - Extract the payment amount from the BOLT11 invoice
- Estimate fees - Get Lightning routing fee estimate from Spark
- Find best pool - Select the pool with optimal liquidity for your token → BTC swap
- Execute swap - Swap tokens to BTC via Flashnet AMM
- Pay invoice - Use the received BTC to pay the Lightning invoice
getPayLightningWithTokenQuote() for quotes and payLightningWithToken() for execution.
Getting a Quote
Always get a quote first to see the total cost:Quote Response
Executing Payment
After reviewing the quote, execute the payment:Payment Options
Payment Result
Complete Example
Fee Breakdown
The total token cost includes multiple fee components:- Lightning routing fee - Network fee to route the payment (~0.1-0.5%)
- AMM LP fee - Liquidity provider fee (typically 20 bps)
- Integrator fee - Optional fee for integrators (if specified)
- BTC variable fee - Up to 63 sats adjustment for AMM leaf management
tokenAmountRequired in the quote—what you see is what you pay.
Fee Calculation Example
For a 5000 sat invoice with 20 bps LP fee:Minimum Amounts
Flashnet enforces minimum amounts for swaps:- BTC output: 1,000 sats minimum
- Token input: Varies by token (typically 1 USD equivalent)
Instant Payment with Existing BTC
If you already have BTC in your wallet, you can pay the invoice immediately without waiting for the swap to complete:- Checks if you have enough BTC to cover the invoice + Lightning fee
- If yes: executes swap → pays immediately → swap BTC arrives async
- If no: falls back to normal flow (waits for swap to complete)