闪电网络发送费用估算
要估算发送闪电网络支付的费用,使用 getLightningSendFeeEstimate
。这在进行闪电网络支付前了解潜在的路由成本很有用。请注意:实际评估的费用可能与费用估算不同,因为它将由实际的闪电网络节点路由决定。
// 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);
feeEstimate
响应示例:
{
feeEstimate: {
originalValue: 100,
originalUnit: 'SATOSHI',
preferredCurrencyUnit: 'USD',
preferredCurrencyValueRounded: 0.05,
preferredCurrencyValueApprox: 0.048
}
}
合作退出费用估算
当将资金提取回比特币网络(合作退出)时,您可以使用 getCoopExitFeeEstimate
估算相关费用:
// Get fee estimate for withdrawing to Bitcoin
const exitFeeEstimate = await wallet.getCoopExitFeeEstimate({
amountSats: 10000n,
withdrawalAddress: "bc1...", // Bitcoin address for withdrawal
});
exitFeeEstimate
响应示例:
{
feeEstimate: {
originalValue: 1000,
originalUnit: 'SATOSHI',
preferredCurrencyUnit: 'USD',
preferredCurrencyValueRounded: 0.50,
preferredCurrencyValueApprox: 0.483
}
}
理解费用组成部分
费用估算字段
originalValue
:原始单位(SATOSHI)的费用金额
originalUnit
:原始值的单位(始终为 ‘SATOSHI’)
preferredCurrencyUnit
:转换后的货币单位(例如,‘USD’)
preferredCurrencyValueRounded
:首选货币的四舍五入值
preferredCurrencyValueApprox
:首选货币的近似值
最佳实践
- 在不同网络条件下监控费用变化
- 在交易计划中包含费用估算
下一步
了解费用估算后,您可以:
需要帮助?