handle 0 empty accounts

This commit is contained in:
thrishank
2025-01-04 23:31:01 +05:30
parent c08ae5bb04
commit e8147da5fe

View File

@@ -30,14 +30,20 @@ export async function closeEmptyTokenAccounts(
spl_token.forEach((instruction) => transaction.add(instruction));
token_2022.forEach((instruction) => transaction.add(instruction));
const size = spl_token.length + token_2022.length;
if (size === 0) {
return {
signature: "",
size: 0,
};
}
const signature = await agent.connection.sendTransaction(transaction, [
agent.wallet,
]);
const size = spl_token.length + token_2022.length;
return {
signature,
size,
};
return { signature, size };
} catch (error) {
throw new Error(`Error closing empty token accounts: ${error}`);
}