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.
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
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.
- All
- Single chain
- Specific 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);
}
}
import {IClaimableSwap} from "@atomiqlabs/sdk";
import {StarknetChainType} from "@atomiqlabs/chain-starknet";
// Returns all claimable swaps for a given smart chain (swaps between BTC/Lightning and the given smart chain)
const starknetClaimableSwaps: IClaimableSwap<StarknetChainType>[] = await swapper.getClaimableSwaps("STARKNET");
for (let swap of starknetClaimableSwaps) {
// We can also additionally check if the swap is indeed created for the signer
if (swap.getOutputAddress() === starknetSigner.getAddress()) {
await swap.claim(starknetSigner);
}
}
import {IClaimableSwap} from "@atomiqlabs/sdk";
import {StarknetChainType} from "@atomiqlabs/chain-starknet";
// Returns claimable swaps for a specific signer address
const signerClaimableSwaps: IClaimableSwap<StarknetChainType>[] = await swapper.getClaimableSwaps("STARKNET", starknetSigner.getAddress());
for (let swap of signerClaimableSwaps) {
await swap.claim(starknetSigner);
}
Type of the signer object passed to the claim() function is dependent on the destination network:
- For Solana swaps: SolanaSigner, or native
@coral-xyz/anchorWallet - For Starknet swaps: StarknetSigner, StarknetBrowserSigner, or native
starknetAccount - For EVM swaps: EVMSigner, or native
ethersSigner
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();
The transactions returned by the txsClaim() function use the following types:
- For Solana, uses the SolanaTx type
- For Starknet, uses the StarknetTx type
- For EVM, uses the
ethersTransactionRequest type
For more information about how to sign and send these transactions manually refer to the Manual Transactions page.
API Reference
- isClaimable - Check claim status
- waitTillClaimed - Wait for automatic settlement or manual claim
- claim - Execute claim
- txsClaim - Get claim transactions
- getClaimableSwaps - Get all claimable swaps