mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-18 07:36:46 +00:00
handle 0 empty accounts
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user