Typescript
SPL Token with Web3.js

SPL Token with Web3.js

Close Account Instruction

Closes a token account and transfers its remaining SOL rent to a destination account. The token account must have zero balance unless it's a native SOL account.

From Token2022 it's possible to close a Mint account that has a supply of 0

Before we can mint any token, we'll need to already have:

  • Initialized a Mint account
  • Initialized a Token account or Associated Token account that doesn't have any token inside.

Raw Instruction

By using just "raw" instruction without any abstraction, this is how closing an account would look like:

// Delegate an ATA 
const closeAccountInstruction = createCloseAccountInstruction(
    tokenAccount // account
    keypair.publickey // destination
    keypair.publickey // authority
);
 
const transaction = new Transaction().add(closeAccountInstruction);
 
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
 
console.log(`Token accounts closed! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);

Abstracted Instruction

This is how the same instructions would look like abstracted away with the closeAccount() instruction:

  let tx = await closeAccount(
    connection,
    keypair,
    ata.address, // token Account
    keypair.publicKey, // destination
    keypair.publicKey, // authority
);
 
console.log(`Succesfully Closed!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)
Contents
View Source
Blueshift © 2025Commit: dd6c76d