Refunding Payments

The SDK handles refunding of payments that have failed automatically, though sometimes it is necessary for the user to intervene in order to recover their funds.

Bitcoin

In order to manually execute a Bitcoin refund, you need to supply an on-chain BTC address to which the refunded amount will be sent. The following code will retrieve the refundable swaps:

Rust
let refundables = sdk.list_refundables().await?;
Swift
let refundables = try? sdk.listRefundables()
Kotlin
try {
    val refundables = sdk.listRefundables()
} catch (e: Exception) {
    // handle error
}
React Native
const refundables = await listRefundables()
Dart
List<RefundableSwap> refundables = await breezSDKLiquid.instance!.listRefundables();
Python
try:
    refundables = sdk.list_refundables()
    return refundables
except Exception as error:
    logging.error(error)
    raise
Go
if refundables, err := sdk.ListRefundables(); err == nil {
    log.Printf("%#v", refundables)
}
C#
try
{
    var refundables = sdk.ListRefundables();
}
catch (Exception)
{
    // Handle error
}

Once you have a refundable swap in hand, use the following code to execute a refund:

Rust
let destination_address = "...".into();
let sat_per_vbyte = refund_tx_fee_rate;

sdk.refund(&RefundRequest {
    swap_address: refundable.swap_address,
    refund_address: destination_address,
    sat_per_vbyte,
})
.await?;
Swift
let destinationAddress = "..."
let response = try? sdk.refund(req: RefundRequest(
    swapAddress: refundable.swapAddress,
    refundAddress: destinationAddress,
    satPerVbyte: satPerVbyte))
Kotlin
val destinationAddress = "..."
val satPerVbyte = refundTxFeeRate
try {
    sdk.refund(RefundRequest(refundable.swapAddress, destinationAddress, satPerVbyte))
} catch (e: Exception) {
    // handle error
}
React Native
const destinationAddress = '...'
const satPerVbyte = refundTxFeeRate

const refundResponse = await refund({
  swapAddress: refundable.swapAddress,
  refundAddress: destinationAddress,
  satPerVbyte
})
Dart
String destinationAddress = "...";
int satPerVbyte = refundTxFeeRate;

RefundRequest req = RefundRequest(
  swapAddress: refundable.swapAddress,
  refundAddress: destinationAddress,
  satPerVbyte: satPerVbyte,
);
RefundResponse resp = await breezSDKLiquid.instance!.refund(req: req);
print(resp.refundTxId);
Python
destination_address = "..."
sat_per_vbyte = refund_txfee_rate
try:
    sdk.refund(RefundRequest(refundable.swap_address, destination_address, sat_per_vbyte))
except Exception as error:
    logging.error(error)
    raise
Go
destinationAddress := "..."
satPerVbyte := refundTxFeeRate
refundRequest := breez_sdk_liquid.RefundRequest{
    SwapAddress:   refundable.SwapAddress,
    RefundAddress: destinationAddress,
    SatPerVbyte:   satPerVbyte,
}

if result, err := sdk.Refund(refundRequest); err == nil {
    log.Printf("%v", result)
}
C#
var destinationAddress = "...";
var satPerVbyte = refundTxFeeRate;
try
{
    sdk.Refund(
        new RefundRequest(
            refundable.swapAddress, 
            destinationAddress, 
            satPerVbyte));
}
catch (Exception)
{
    // Handle error
}

Developer note

A refund can be attempted several times. A common scenario where this is useful is if the initial refund transaction takes too long to mine, your application's users can be offered the ability to re-trigger the refund with a higher feerate.