How to Close Token Accounts With the spl-token CLI
Updated · 5 min read
If you prefer not to connect your wallet to any website, the official spl-token command line tool can close empty accounts directly. This guide is for users comfortable with a terminal and a file-system keypair.
List your token accounts
After installing the Solana CLI tools and spl-token, point the CLI at mainnet and your keypair, then list your accounts. The output shows each mint and its balance, which makes zero-balance accounts easy to spot.
solana config set --url mainnet-betaspl-token accountsspl-token accounts --verbose (shows the account addresses)
Close a single account
Close a specific empty account by its address. The rent goes back to the keypair's wallet by default.
spl-token close --address <TOKEN_ACCOUNT_ADDRESS>
Clean up everything at once
The gc subcommand looks for unnecessary token accounts owned by your keypair and closes the empty ones. Review the CLI help output first so you understand what it will do in your version.
spl-token gc --helpspl-token gc
CLI vs a web tool
The CLI requires the private key to live in a keypair file, which many people avoid for their main wallet. Browser and hardware wallets work better with a web interface, where every transaction is shown in your wallet before signing.
Check your wallet for locked SOL
Scan any Solana address for empty token accounts and see exactly how much rent you can reclaim. Free to check, non-custodial to close.
Frequently asked questions
Does the CLI charge a fee?
Only the normal Solana network fee. There is no protocol fee when you close accounts yourself.
Can I use the CLI with a Ledger?
The Solana CLI supports hardware wallets through a usb:// keypair URL, but setup is more involved than a browser wallet.
