Skip to content

​What Does Closing a Token Account Do?

Closing a token account deletes the account and transfers all of its lamports, including its refundable minimum storage balance, to a destination account. The token balance must be zero before the account can close. A frozen account can still be closed if the frozen account’s token balance is zero. Wrapped SOL token accounts are the exception and can be closed with a token balance to reclaim the underlying SOL. The account owner or the account’s close authority signs the close instruction and selects the destination. The account that paid to create an ATA does not automatically receive the recovered balance.

​How to Close a Token Account

Closing a token account uses the Token Program’s CloseAccount instruction. The CloseAccount instruction transfers the source account’s lamports to a destination account, clears the source account, and deletes the source account. The Token Extension Program applies additional close checks for certain extensions, but the base close flow is the same.

​Source Reference

ItemDescriptionToken ProgramToken Extension Program
AccountThe token account state stores the balance, native status, and close authority used during account closure.SourceSource
CloseAccountAn instruction that closes a token account and transfers the token account’s lamports to a destination account.SourceSource
process_close_accountShared processor logic for token-account closure.SourceSource

​Kit

These examples use @solana/kit.

​Web3.js v3

These examples use the class-based @solana/web3.js v3 API with @solana-program instruction builders.
Instructions

​Rust

Add these dependencies to Cargo.toml (tested with Rust 1.89 and 1.98):
Cargo.toml
Rust

​Python

This example uses solana (solana-py) 0.41 and solders:
Terminal
Python

​Web3.js (legacy)

These examples use legacy @solana/web3.js 1.x with @solana/spl-token.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.