Quickstart
Reclaim a wallet's rent from empty token accounts with the SDK, from scan to submit.
Start on the preview sandbox, which uses Solana devnet and bnc_test_ organization keys. Use a throwaway wallet with devnet assets; no production balances are needed. Once preview is deployed, set its public API origin before running the examples:
export BURN_AND_CLAIM_API_URL="https://preview-api.burnandclaim.com"This walks through a cleanup with @burnandclaim/sdk, Burn & Claim's TypeScript client. It runs in Node 22 or later and every bundler. In a browser, read Calling from a browser first.
npm install @burnandclaim/sdkScan the wallet
A scan lists every asset the wallet holds, the actions each can take, and what each action returns and costs. Every amount is a whole number of lamports as a decimal string: read it with BigInt, never Number.
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`)Quote and reclaim
Pick the items: here, every empty token account. A quote prices them against the chain as it is now. reclaim then runs the whole cleanup: it prepares each round, stamps each approval just before your wallet signs it, submits what the wallet signed, and carries what didn't fit into the next round.
const items = scan.assets
.filter((asset) => asset.kind === 'empty_account' && !asset.frozen)
.map((asset) => ({ assetId: asset.id, action: 'close' as const }))
const quote = await bnc.quote({ wallet, items, transactionVersions: [0, 1] })
console.log(`${quote.totals.netLamports} lamports back, in ${quote.approvals} approval(s)`)
const result = await reclaim(bnc, {
wallet,
items,
transactionVersions: [0, 1],
signTransactions: signWithYourWallet,
onProgress: (event) => {
if (event.type === 'approval') console.log(`Approval ${event.number} of ${event.of}`)
},
})
console.log(`${result.totals.netLamports} lamports reclaimed`)signTransactions gets each transaction's wire bytes, unsigned, with the wallet as the fee payer, and answers them signed, in the same order. It must never send them: the API co-signs and sends every transaction. With a Wallet Standard wallet, it's the wallet's solana:signTransaction feature. transactionVersions lists the versions the wallet signs: with version 1 the API packs far more items into each transaction.
What came back
reclaim answers what happened to every item:
| Field | What it holds |
|---|---|
confirmed | Every transaction that landed, with its fee snapshot |
failedOnChain | Transactions that landed and failed: the runtime reverted everything in them, and the wallet paid the network fee |
unconfirmed | Signatures whose outcome isn't known yet. Look each one up with bnc.transaction(signature) before trying its items again |
skipped | Items the API wouldn't build, with why |
left | Items not done: rounds ran out, or an earlier approval of theirs can still land |
totals | The sum over what landed |
Next: How a cleanup works explains each step, and the cookbook has more recipes.