Burn & Claim’s new API is in preview: these pages describe it as it will be at launch.
Burn & Claim Docs
SDKCookbook

Scan a wallet

List what a wallet can close or burn, and pick what the Burn & Claim app would.

A scan lists every asset in the wallet with each action it can take and what that action returns and costs. defaultAction is what the Burn & Claim app would do with an asset, where it has one.

Set the preview API variable from the quickstart before running this recipe.

examples/scan-a-wallet.ts
const baseUrl = process.env.BURN_AND_CLAIM_API_URL
if (!baseUrl) throw new Error('Set BURN_AND_CLAIM_API_URL from the preview quickstart.')
const bnc = createClient({ baseUrl })

const scan = await bnc.scan(wallet)
for (const asset of scan.assets) {
  for (const option of asset.actions) {
    console.log(asset.id, asset.kind, option.action, option.netLamports)
  }
}
console.log(`Reclaimable: ${scan.totals.reclaimableLamports} lamports`)

const items: Selection[] = scan.assets.flatMap((asset) =>
  asset.defaultAction === null
    ? []
    : [
        {
          assetId: asset.id,
          // A scan's actions may grow; a selection names one this SDK knows.
          action: asset.defaultAction as Selection['action'],
          ...(asset.defaultAction === 'burn' ? { expectedAmount: asset.amount } : {}),
        },
      ],
)

A burn names the exact amount the scan saw (expectedAmount), so it burns that amount or reverts: if the balance moved since the scan, scan again. An asset with a blockedReason (frozen, unsupported) has no actions.

Addresses a scan refuses

A scan reads the whole wallet, so some addresses can't be scanned. The System Program, a sysvar, a program or the incinerator is refused before anything is read, and so is a wallet holding more than 5,000 accounts of one kind (token accounts, DAS assets, ZK-compressed tokens or stake accounts): it is refused whole, never scanned in part. Both answer the wallet_too_large problem (422), and so does a quote or a round for the same wallet. Scanning again changes nothing: tell the person the address holds too many accounts to clean up here, and to connect a wallet they sign with. A scan also ends within 40 seconds; past that the JSON answer is upstream_timeout, which is worth one retry a minute later.

Protected assets

Each asset carries protection. When protection.protected is true, the asset holds the person's own money beyond its rent: an LP token, a liquidity position, a staking or lending receipt, a vault share, a name, a pass or another item a market price alone would show as $0. Burn & Claim recognizes it by its platform's program, never by its name. platform names it, holds says what burning it would lose, valueUsd and valueLamports say what it is worth (null when that can't be computed, never 0 for unknown), valueBasis says where the value comes from, and redeemUrl is the platform's own page to withdraw it on, on mainnet.

Never select a protected asset for the person: show it, and let them withdraw it at its platform first.

examples/scan-a-wallet.ts
const keep = scan.assets.filter((asset) => asset.protection.protected)
for (const asset of keep) {
  const { platform, holds, valueUsd, redeemUrl } = asset.protection
  console.log(asset.id, platform?.name ?? 'item', holds, valueUsd ?? 'unknown', redeemUrl ?? '')
}

On this page