Prerequisites

Lightning Send Fee Estimates

To estimate fees for sending Lightning payments, use getLightningSendFeeEstimate. This is useful before making a Lightning payment to understand the associated costs:

// Get fee estimate for a Lightning payment
const feeEstimate = await wallet.getLightningSendFeeEstimate({
  encodedInvoice: "lnbc...", // Your BOLT11 invoice string
});

console.log("Lightning send fee estimate:", feeEstimate);
// Example output:
// {
//   feeEstimate: {
//     originalValue: 100,
//     originalUnit: 'SATOSHI',
//     preferredCurrencyUnit: 'USD',
//     preferredCurrencyValueRounded: 0.05,
//     preferredCurrencyValueApprox: 0.048
//   }
// }

Cooperative Exit Fee Estimates

When withdrawing funds back to the Bitcoin network (cooperative exit), you can estimate the associated fees using getCoopExitFeeEstimate:

// Get fee estimate for withdrawing to Bitcoin
const exitFeeEstimate = await wallet.getCoopExitFeeEstimate({
  amountSats: 10000,
  withdrawalAddress: "bc1...", // Bitcoin address for withdrawal
});

console.log("Cooperative exit fee estimate:", exitFeeEstimate);
// Example output:
// {
//   feeEstimate: {
//     originalValue: 1000,
//     originalUnit: 'SATOSHI',
//     preferredCurrencyUnit: 'USD',
//     preferredCurrencyValueRounded: 0.50,
//     preferredCurrencyValueApprox: 0.483
//   }
// }

Understanding Fee Components

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

Best Practices

  • Always check fee estimates before making transactions
  • Consider both SATOSHI and USD values when planning transactions
  • Monitor fee variations during different network conditions
  • Include fee estimates in your transaction planning

Next Steps

After understanding fee estimates, you can:

Need Help?