Handling channel closures

When channels are closed (due to a misbehaving node or by the LSP), the remaining funds are sent to an on-chain address. To redeem these funds please follow the steps below.

Preparing the transaction

Prepare the transaction to retrieve its weight and the calculated fees before broadcasting it:

Rust
let sat_per_vbyte = fee_rate;
let destination_address = String::from("bc1..");
sdk.prepare_redeem_onchain_funds(PrepareRedeemOnchainFundsRequest {
    sat_per_vbyte,
    to_address: destination_address,
})
.await?;
Swift
let satPerVbyte = feeRate
let req = PrepareRedeemOnchainFundsRequest(toAddress: "bc1..", satPerVbyte: satPerVbyte)
let prepareRedeemOnchainFundsResponse = try? sdk.prepareRedeemOnchainFunds(req: req)
Kotlin
 val satPerVbyte = feeRate
 var destinationAddress = "bc1.."
 try {
    val req = PrepareRedeemOnchainFundsRequest(destinationAddress, satPerVbyte)
    val prepareRedeemOnchainFundsResp = sdk.prepareRedeemOnchainFunds(req)
 }
 catch (e: Exception) {
    // handle error
}
React Native
try {
  const toAddress = 'bc1..'
  const satPerVbyte = feeRate
  const prepareRedeemOnchainFundsResp = await prepareRedeemOnchainFunds({ toAddress, satPerVbyte })
} catch (err) {
  console.error(err)
}
Dart
PrepareRedeemOnchainFundsRequest req = PrepareRedeemOnchainFundsRequest(
  toAddress: "bc1..",
  satPerVbyte: satPerVbyte,
);
final resp = await BreezSDK().prepareRedeemOnchainFunds(req: req);
Python
destination_address = "bc1.."
sat_per_vbyte = fee_rate
req = breez_sdk.PrepareRedeemOnchainFundsRequest(destination_address, sat_per_vbyte)
result =  sdk_services.prepare_redeem_onchain_funds(req)
Go
satPerVbyte := feeRate
destinationAddress := "bc1.."
req := breez_sdk.PrepareRedeemOnchainFundsRequest{SatPerVbyte: satPerVbyte, ToAddress: destinationAddress}
if prepareRedeemOnchainFundsResponse, err := sdk.PrepareRedeemOnchainFunds(req); err == nil {
    log.Printf("PrepareRedeemOnchainFundsRequest is %#v", prepareRedeemOnchainFundsResponse)
}
C#
var destinationAddress = "bc1..";
var satPerVbyte = feeRate; 
try 
{
    var prepareRedeemOnchainFundsResp = sdk.PrepareRedeemOnchainFunds(
        new PrepareRedeemOnchainFundsRequest(
            destinationAddress,
            satPerVbyte
        ));
}
catch (Exception)
{
    // Handle error
}

Redeeming the on-chain funds

Redeem the on-chain funds by broadcasting the transaction to the network:

Rust
sdk.redeem_onchain_funds(RedeemOnchainFundsRequest {
    sat_per_vbyte,
    to_address,
})
.await?;
Swift
let satPerVbyte = feeRate
let req = RedeemOnchainFundsRequest(toAddress: "bc1..", satPerVbyte: satPerVbyte)
let redeemOnchainFundsResponse = try? sdk.redeemOnchainFunds(req: req)
Kotlin
 try {
    val req = RedeemOnchainFundsRequest(toAddress, satPerVbyte)
    val redeemOnchainFundsResp = sdk.redeemOnchainFunds(req)
 }
 catch (e: Exception) {
    // handle error
}
React Native
try {
  const redeemOnchainFundsResp = await redeemOnchainFunds({ toAddress, satPerVbyte })
} catch (err) {
  console.error(err)
}
Dart
RedeemOnchainFundsRequest req = RedeemOnchainFundsRequest(
  toAddress: "bc1..",
  satPerVbyte: satPerVbyte,
);
final resp = await BreezSDK().redeemOnchainFunds(req: req);
Python
req = breez_sdk.RedeemOnchainFundsRequest(to_address, fee_rate)
result = sdk_services.redeem_onchain_funds(req)
Go
req := breez_sdk.RedeemOnchainFundsRequest{SatPerVbyte: satPerVbyte, ToAddress: toAddress}
if redeemOnchainFundsResponse, err := sdk.RedeemOnchainFunds(req); err == nil {
    log.Printf("RedeemOnchainFunds error %#v", redeemOnchainFundsResponse)
}
C#
try 
{
    var redeemOnchainFundsResp = sdk.RedeemOnchainFunds(
        new RedeemOnchainFundsRequest(
            toAddress,
            satPerVbyte
        ));
}
catch (Exception)
{
    // Handle error
}