Learn how to estimate fees for different operations in your Spark wallet. This guide covers Lightning payments, cooperative exits, and swap operations.
Fee Structure Overview
Below is a breakdown of fees for different transaction types on Spark:
For Bitcoin
Transaction Type Fee structure L1 to Spark On-chain fee paid by the user Spark to Spark Free. Small flat fee coming in 6-12 months Spark to Lightning 0.25% + routing fee Lightning to Spark 0.15% Exit to L1 L1 broadcast fee x 2 Unilateral Exit On-chain fee paid by the user
For BTKN assets
Transaction Type Fee structure L1 to Spark On-chain fee paid by the user Spark to Spark Free. Small flat fee coming in 6-12 months Unilateral Exit On-chain fee + bond locked by user
Some of the fees are sourced directly from the Lightspark SSP, specifically for Spark–Lightning interactions and exits back to L1. Lightspark is the first SSP on Spark, but the system is open. Anyone can run an SSP (SSP specs coming soon). If you’re an SSP, reach out, and we’ll include your fee structure.
Fee Estimation Flow
The complete process for estimating fees before making transactions:
Choose Operation Type
Determine which type of operation you want to estimate fees for. // Lightning payment
const lightningInvoice = "lnbc..." ;
// Cooperative exit (withdrawal to L1)
const withdrawalAmount = 10000 ;
const withdrawalAddress = "bc1p..." ;
// Swap operation
const swapAmount = 5000 ;
Get Fee Estimate
Call the appropriate fee estimation method. // Lightning send fee estimate
const lightningFee = await wallet . getLightningSendFeeEstimate ({
encodedInvoice: lightningInvoice
});
// Cooperative exit fee estimate
const exitFee = await wallet . getWithdrawalFeeQuote ({
amountSats: withdrawalAmount ,
withdrawalAddress: withdrawalAddress
});
// Swap fee estimate
const swapFee = await wallet . getSwapFeeEstimate ( swapAmount );
Review Fee Details
Examine the fee estimate response to understand costs. console . log ( "Fee estimate:" , feeEstimate . feeEstimate );
console . log ( "Original value:" , feeEstimate . feeEstimate . originalValue , "sats" );
console . log ( "USD equivalent:" , feeEstimate . feeEstimate . preferredCurrencyValueRounded , "USD" );
Proceed with Transaction
Use the fee estimate to set appropriate limits for your transaction. // Use fee estimate for Lightning payment
const payment = await wallet . payLightningInvoice ({
invoice: lightningInvoice ,
maxFeeSats: lightningFee . feeEstimate . originalValue + 5 // Add buffer
});
Lightning Send Fee Estimates
Estimate fees for sending Lightning payments before making the transaction.
getLightningSendFeeEstimate(params)
Gets an estimated fee for sending a Lightning payment. Note: the actual fee assessed may be different from the fee estimate as it will be determined by the actual Lightning node routing.
const feeEstimate = await wallet . getLightningSendFeeEstimate ({
encodedInvoice: "lnbcrt1u1pnm7ammpp4v84f05tl0kzt6g95g056athdpp8f8azvg6d7epz74z562ymer9jqsp5nc50gazvp0e98u42jlu653rw0eutcl067nqq924hf89q4la4kd9sxq9z0rgqnp4qdnmwu8v22cvq9xsv2l05cn9rre7xlcgdtntxawf8m0zxq3qemgzqrzjqtr2vd60g57hu63rdqk87u3clac6jlfhej4kldrrjvfcw3mphcw8sqqqqrj0q7ew45qqqqqqqqqqqqqq9qcqzpgdq5w3jhxapqd9h8vmmfvdjs9qyyssqj7lf2w4m587g04n4t0ferdv0vnwftzca0xuc9yxycng78cnhrvmyw2mzaa8t76jskpypqnwqhp9xh0vnwxz90jytd34vrmhcngsnl8qplz7ylk"
});
console . log ( "Lightning send fee estimate:" , feeEstimate );
The BOLT11-encoded Lightning invoice
feeEstimate
LightningSendFeeEstimate
required
Object containing fee estimate details
Example Response
{
feeEstimate : {
originalValue : 100 ,
originalUnit : 'SATOSHI' ,
preferredCurrencyUnit : 'USD' ,
preferredCurrencyValueRounded : 0.05 ,
preferredCurrencyValueApprox : 0.048
}
}
Cooperative Exit Fee Estimates
Estimate fees for withdrawing funds back to the Bitcoin network (cooperative exit).
getWithdrawalFeeQuote(params)
Gets a fee quote for a cooperative exit (on-chain withdrawal). The quote includes options for different speeds and an expiry time and must be passed to withdraw before it expires.
const exitFeeEstimate = await wallet . getWithdrawalFeeQuote ({
amountSats: 10000 ,
withdrawalAddress: "bc1p5d7rjq7g6rdk2yhzks9smtbqtedr4dekq08ge8ztwac72sfr9rusxg3297"
});
console . log ( "Cooperative exit fee estimate:" , exitFeeEstimate );
The amount in satoshis to withdraw
The Bitcoin address where the funds should be sent
exitFeeEstimate
WithdrawalFeeQuote | null
required
A fee quote for the withdrawal, or null if not available
Example Response
{
feeEstimate : {
originalValue : 1000 ,
originalUnit : 'SATOSHI' ,
preferredCurrencyUnit : 'USD' ,
preferredCurrencyValueRounded : 0.50 ,
preferredCurrencyValueApprox : 0.483
}
}
Swap Fee Estimates
Estimate fees for swap operations between different token types.
getSwapFeeEstimate(amountSats)
Gets the estimated fee for a swap of leaves.
const swapFeeEstimate = await wallet . getSwapFeeEstimate ( 5000 );
console . log ( "Swap fee estimate:" , swapFeeEstimate );
The amount of sats to swap
swapFeeEstimate
LeavesSwapFeeEstimateOutput
required
The estimated fee for the swap operation
Understanding Fee Components
All fee estimates return a consistent structure with the following fields:
Fee Estimate Fields
originalValue The fee amount in the original unit (SATOSHI)
originalUnit The unit of the original value (always ‘SATOSHI’)
preferredCurrencyUnit The converted currency unit (e.g., ‘USD’)
preferredCurrencyValueRounded The rounded value in preferred currency
preferredCurrencyValueApprox The approximate value in preferred currency
When Fees Apply
Understanding when different types of fees are charged:
Lightning Payments:
Routing fees for Lightning Network transactions
Fees vary based on network conditions and routing path
Estimated fees may differ from actual fees charged
Cooperative Exits (L1 Withdrawals):
Bitcoin network transaction fees
Different speeds available (fast, medium, slow)
Fees increase with urgency
Swap Operations:
Fees for converting between different token types
Based on current market conditions
May include liquidity provider fees
Fee Deduction Options
For cooperative exits, you can choose how fees are handled:
Deduct Fee from Withdrawal Amount
When deductFeeFromWithdrawalAmount is set to true:
const withdrawal = await wallet . withdraw ({
onchainAddress: "bc1p..." ,
exitSpeed: "medium" ,
amountSats: 10000 , // This is the net amount you'll receive
feeQuote: feeQuote ,
deductFeeFromWithdrawalAmount: true // Fee deducted from amount
});
// You receive: 10000 sats - fee
Pay Fee Separately
When deductFeeFromWithdrawalAmount is set to false:
const withdrawal = await wallet . withdraw ({
onchainAddress: "bc1p..." ,
exitSpeed: "medium" ,
amountSats: 10000 , // This is the gross amount you'll receive
feeQuote: feeQuote ,
deductFeeFromWithdrawalAmount: false // Fee paid separately
});
// You receive: 10000 sats (fee paid from wallet balance)
Best Practices
Monitor fee variations - Fees can change based on network conditions
Include fee estimates in planning - Always factor in estimated fees when planning transactions
Add buffer to estimates - Add a small buffer to fee estimates for Lightning payments
Compare fee options - For withdrawals, compare different speed options
Check fee quotes regularly - Fee quotes expire, get fresh ones before transactions
Complete Example
import { SparkWallet } from "@buildonspark/spark-sdk" ;
async function estimateAllFees () {
const { wallet } = await SparkWallet . initialize ({
options: { network: "REGTEST" }
});
try {
// 1. Lightning send fee estimate
const lightningInvoice = "lnbcrt1u1pnm7ammpp4v84f05tl0kzt6g95g056athdpp8f8azvg6d7epz74z562ymer9jqsp5nc50gazvp0e98u42jlu653rw0eutcl067nqq924hf89q4la4kd9sxq9z0rgqnp4qdnmwu8v22cvq9xsv2l05cn9rre7xlcgdtntxawf8m0zxq3qemgzqrzjqtr2vd60g57hu63rdqk87u3clac6jlfhej4kldrrjvfcw3mphcw8sqqqqrj0q7ew45qqqqqqqqqqqqqq9qcqzpgdq5w3jhxapqd9h8vmmfvdjs9qyyssqj7lf2w4m587g04n4t0ferdv0vnwftzca0xuc9yxycng78cnhrvmyw2mzaa8t76jskpypqnwqhp9xh0vnwxz90jytd34vrmhcngsnl8qplz7ylk" ;
const lightningFee = await wallet . getLightningSendFeeEstimate ({
encodedInvoice: lightningInvoice
});
console . log ( "Lightning fee estimate:" , lightningFee . feeEstimate . originalValue , "sats" );
// 2. Cooperative exit fee estimate
const exitFee = await wallet . getWithdrawalFeeQuote ({
amountSats: 10000 ,
withdrawalAddress: "bc1p5d7rjq7g6rdk2yhzks9smtbqtedr4dekq08ge8ztwac72sfr9rusxg3297"
});
if ( exitFee ) {
console . log ( "Exit fee estimate:" , exitFee . fast , "sats (fast)" );
console . log ( "Exit fee estimate:" , exitFee . medium , "sats (medium)" );
console . log ( "Exit fee estimate:" , exitFee . slow , "sats (slow)" );
}
// 3. Swap fee estimate
const swapFee = await wallet . getSwapFeeEstimate ( 5000 );
console . log ( "Swap fee estimate:" , swapFee );
// 4. Use estimates for actual transactions
const payment = await wallet . payLightningInvoice ({
invoice: lightningInvoice ,
maxFeeSats: lightningFee . feeEstimate . originalValue + 5 // Add 5 sats buffer
});
console . log ( "Lightning payment initiated with fee buffer" );
} catch ( error ) {
console . error ( "Fee estimation failed:" , error );
}
}