Skip to main content

Claiming

For swaps in the Bitcoin (on-chain or Lightning) → Smart Chain direction, the SDK normally handles claiming automatically via watchtower services.

Having to claim (or settle) the swap manually is an edge-case that only happens when the automatic settlement service (watchtower) didn't settle the swap.

Runnable Example

See the complete working example: utils/pastSwaps.ts

Checking Claimable Status

Check if a swap is claimable with the isClaimable() function exposed in SpvFromBTCSwap, FromBTCSwap, FromBTCLNAutoSwap and FromBTCLNSwap classes. You can additionally also wait for the automatic settlement before attempting to claim manually with the waitTillClaimed() function.

// Check if swap needs manual claiming
if (swap.isClaimable()) {
// Optionally wait for automatic settlement for 60 seconds
await swap.waitTillClaimed(60);
// Claim with a signer object
await swap.claim(signer);
}

Get All Claimable Swaps

tip

It's good practice to check for claimable swaps when your app starts and also periodically if your app is long-running. You can then either claim the swaps automatically or prompt the user to authorize the claim.

To retrieve all the swaps that are currently claimable call the getClaimableSwaps() function on the swapper, which returns swaps implementing the IClaimableSwap interface. You can also pass in the chain identifier and signer address to retrieve swaps only for that respective smart chain and/or signer.

import {IClaimableSwap} from "@atomiqlabs/sdk";

// Returns all claimable swaps from storage if no argument is passed
const allClaimableSwaps: IClaimableSwap[] = await swapper.getClaimableSwaps();
// You can check the respective swap's chain by reading its chainIdentifier property
for (let swap of allClaimableSwaps) {
const chainId = swap.chainIdentifier; // Retrieves smart chain type of the swap, e.g.: SOLANA, STARKNET, CITREA, ...
// Retrieve the relevant destination chain signer for the chainId
const signer = smartChainSigners[chainId];
// We can also additionally check if the swap is indeed created for the signer
if (swap.getOutputAddress() === signer.getAddress()) {
await swap.claim(signer);
}
}
info

Type of the signer object passed to the claim() function is dependent on the destination network:

Manually Signing Transactions

You can alternatively use the txsClaim() function to retrieve the smart chain transactions that you can then sign and send manually:

const txsClaim = await swap.txsClaim();
... // Sign and send claim transactions here
// Important to wait till SDK processes the swap claim and updates the swap state
await swap.waitTillClaimed();
info

The transactions returned by the txsClaim() function use the following types:

For more information about how to sign and send these transactions manually refer to the Manual Transactions page.

API Reference