Lendasat LogoLendasat Docs
Recovery

Recover Swaps from Seed

Restore and recover pending swaps using your mnemonic seed phrase.

Backup Your Mnemonic: Always store your mnemonic seed phrase securely. It's the only way to recover funds if you lose access to your device.

When to Use Recovery

Recovery is needed when:

  • You cleared browser data (IndexedDB) or app storage
  • You're moving to a new device
  • App reinstallation cleared local storage
  • You want to check for missed swaps
  • Testing or debugging swap issues

Recover Swaps

Use the xpub derived from your mnemonic to query the API for associated swaps:

import { Client, IdbWalletStorage, IdbSwapStorage } from "@lendasat/lendaswap-sdk-pure";

// Initialize client with your mnemonic
const client = await Client.builder()
  .withSignerStorage(new IdbWalletStorage())
  .withSwapStorage(new IdbSwapStorage())
  .withMnemonic("your twelve word mnemonic phrase ...")
  .build();

// Recover all swaps from the server
const recovered = await client.recoverSwaps();
console.log(`Recovered ${recovered.length} swaps`);

Process Recovered Swaps

Handle each recovered swap based on its current status:

const swaps = await client.listAllSwaps();

for (const stored of swaps) {
  const swap = stored.response;
  switch (swap.status) {
    case "serverfunded":
      console.log(`Swap ${stored.swapId}: Ready to claim!`);
      await client.claim(stored.swapId);
      break;
    case "clientfundedserverrefunded":
      console.log(`Swap ${stored.swapId}: Needs refund`);
      break;
    case "clientredeemed":
      console.log(`Swap ${stored.swapId}: Complete`);
      break;
    default:
      console.log(`Swap ${stored.swapId}: ${swap.status}`);
  }
}

Best Practices

Regular Backups: While recovery from seed works, having regular exports of your swap data can speed up the recovery process.

  1. Secure your mnemonic - Store it offline in multiple secure locations
  2. Test recovery - Periodically verify you can recover with your seed
  3. Act quickly - Recovered swaps may have time-sensitive actions
  4. Check all statuses - Don't assume swaps are complete without verifying
  5. Keep records - Export swap data periodically for faster recovery