# 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.

tip

See the complete working example: [utils/pastSwaps.ts](https://github.com/atomiqlabs/atomiq-sdk-demo/blob/main/src/utils/pastSwaps.ts)

## Checking Claimable Status

Check if a swap is claimable with the [`isClaimable()`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#isclaimable) function exposed in [SpvFromBTCSwap](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/SpvFromBTCSwap), [FromBTCSwap](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/FromBTCSwap), [FromBTCLNAutoSwap](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/FromBTCLNAutoSwap) and [FromBTCLNSwap](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/FromBTCLNSwap) classes. You can additionally also wait for the automatic settlement before attempting to claim manually with the [`waitTillClaimed()`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#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()`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Swapper#getclaimableswaps) function on the swapper, which returns swaps implementing the [`IClaimableSwap`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/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);

}
```

info

Type of the signer object passed to the [`claim()`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#claim) function is dependent on the destination network:

* For **Solana** swaps: [SolanaSigner](https://docs.atomiq.exchange/sdk-reference/api/atomiq-chain-solana/src/classes/SolanaSigner), or native `@coral-xyz/anchor` [Wallet](https://solana-foundation.github.io/anchor/ts/classes/Wallet.html)
* For **Starknet** swaps: [StarknetSigner](https://docs.atomiq.exchange/sdk-reference/api/atomiq-chain-starknet/src/classes/StarknetSigner), [StarknetBrowserSigner](https://docs.atomiq.exchange/sdk-reference/api/atomiq-chain-starknet/src/classes/StarknetBrowserSigner), or native `starknet` [Account](https://starknetjs.com/docs/API/classes/Account)
* For **EVM** swaps: [EVMSigner](https://docs.atomiq.exchange/sdk-reference/api/atomiq-chain-evm/src/classes/EVMSigner), or native `ethers` [Signer](https://docs.ethers.org/v6/api/providers/#Signer)

## Manually Signing Transactions

You can alternatively use the [`txsClaim()`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#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 **Solana**, uses the [SolanaTx](https://docs.atomiq.exchange/sdk-reference/api/atomiq-chain-solana/src/type-aliases/SolanaTx) type
* For **Starknet**, uses the [StarknetTx](https://docs.atomiq.exchange/sdk-reference/api/atomiq-chain-starknet/src/type-aliases/StarknetTx) type
* For **EVM**, uses the `ethers` [TransactionRequest](https://docs.ethers.org/v6/api/providers/#TransactionRequest) type

For more information about how to sign and send these transactions manually refer to the [Manual Transactions](https://docs.atomiq.exchange/sdk-guide/advanced/manual-transactions.md) page.

## API Reference

* [isClaimable](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#isclaimable) - Check claim status
* [waitTillClaimed](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#waittillclaimed) - Wait for automatic settlement or manual claim
* [claim](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#claim) - Execute claim
* [txsClaim](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/interfaces/IClaimableSwap#txsclaim) - Get claim transactions
* [getClaimableSwaps](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/classes/Swapper#getclaimableswaps) - Get all claimable swaps
