If you want to recover locked SOL from empty token accounts without paying any service fee, the Solana CLI (command-line interface) lets you do exactly that. This guide walks you through the entire process from scratch — installing the tools, connecting your wallet, finding empty accounts, and closing them to get your SOL back. No prior command-line experience required.
TL;DR: The Solana CLI and SPL Token program let you close empty token accounts and recover your locked rent deposits for free (minus a negligible ~0.000005 SOL network fee per transaction). It requires installing software, using a terminal, and running commands — but the result is the same as any recovery tool, with zero service fees. If the CLI feels too technical, SolRecover does the same thing in 60 seconds with a 1.9% fee.
What You'll Need Before Starting
Before we begin, here's what you need:
- A computer running Windows, macOS, or Linux
- An internet connection
- Your Solana wallet's private key — either as a keypair file (a JSON file containing an array of numbers) or your seed phrase (the 12 or 24 words you wrote down when creating your wallet)
- About 15–30 minutes for first-time setup
Important security note: This guide involves using your private key directly on your computer. Make sure your computer is free of malware and that no one is watching your screen. Never paste your seed phrase or private key into any website, chat, or untrusted application.
What Is the Solana CLI?
The Solana CLI is the official command-line tool built by Solana Labs. Think of it as a way to talk directly to the Solana blockchain by typing text commands into a terminal window, instead of clicking buttons in a wallet app.
The terminal (also called the command line, command prompt, or shell) is a program on your computer that lets you run commands by typing them. If you've never used one before, don't worry — this guide tells you exactly what to type at every step.
Where to find the terminal on your computer:
- Windows: Press
Win + R, typecmd, and press Enter. Or search for "Command Prompt" or "PowerShell" in the Start menu. - macOS: Press
Cmd + Space, type "Terminal", and press Enter. - Linux: Press
Ctrl + Alt + T, or search for "Terminal" in your applications.
Open your terminal now and keep it open — you'll use it for the rest of this guide.
Step 1: Install the Solana CLI
The Solana CLI is free and open-source software maintained by Anza (the team behind the Solana validator client). Installation takes a single command.
On macOS or Linux
Copy and paste this entire command into your terminal, then press Enter:
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
You'll see download progress and an installation message. When it finishes, it will tell you to add a line to your PATH. The installer usually prints a message like:
Please update your PATH environment variable to include the solana programs:
PATH="/Users/yourname/.local/share/solana/install/active_release/bin:$PATH"
Copy the PATH=... line it gives you, paste it into your terminal, and press Enter. Then close and reopen your terminal so the changes take effect.
On Windows
Open PowerShell as Administrator (right-click PowerShell in the Start menu and choose "Run as administrator"), then paste:
cmd /c "curl https://release.anza.xyz/stable/solana-install-init-x86_64-pc-windows-msvc.exe --output C:\solana-install-tmp\solana-install-init.exe --create-dirs"
Then run the installer:
C:\solana-install-tmp\solana-install-init.exe stable
Follow the on-screen prompts. When it finishes, close and reopen PowerShell.
Verify the Installation
In your terminal, type:
solana --version
You should see something like solana-cli 2.x.x. If you see an error like "command not found," the PATH wasn't set correctly — try closing and reopening your terminal, or repeat the PATH step above.
Step 2: Install the SPL Token CLI
The SPL Token CLI is a separate tool that handles token-specific operations — including closing empty token accounts. This is the tool that actually recovers your SOL.
Run this command:
cargo install spl-token-cli
Wait — what if you don't have cargo? Cargo is the Rust programming language's package manager. If you get an error saying cargo: command not found, you need to install Rust first:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
On Windows, download and run the installer from https://rustup.rs instead.
After installing Rust, close and reopen your terminal, then run the cargo install spl-token-cli command again.
Note: This installation compiles the tool from source code, which can take 5–10 minutes depending on your computer. You'll see a lot of text scrolling by — that's normal. Wait until you see "Installed" at the end.
Verify the Installation
spl-token --version
You should see a version number. If so, you're ready to proceed.
Step 3: Configure Your RPC Endpoint
The RPC endpoint is the server your CLI talks to in order to read data from and send transactions to the Solana blockchain. By default, the Solana CLI uses the public mainnet endpoint, which can be slow or rate-limited.
Set it to mainnet:
solana config set --url https://api.mainnet-beta.solana.com
You can verify your config anytime with:
solana config get
This will show your RPC URL and other settings.
Tip: If you experience slow responses or errors later, you can use a free RPC endpoint from providers like Helius, QuickNode, or Alchemy. Sign up for a free tier, get your endpoint URL, and replace the URL in the command above.
Step 4: Import Your Wallet
This is the most important step. You need to tell the CLI which wallet to use. There are two ways to do this depending on how you access your wallet.
Option A: Import Using Your Seed Phrase (Most Common)
If you use Phantom, Solflare, Backpack, or any standard Solana wallet, you have a seed phrase (also called a recovery phrase) — the 12 or 24 words you saved when creating the wallet.
Run this command:
solana-keygen recover -o ~/my-solana-wallet.json
The CLI will ask you to enter your seed phrase. Type or paste your words separated by spaces, then press Enter. It will also ask for a "BIP39 passphrase" — if you never set one (most people haven't), just press Enter to skip it.
This creates a keypair file at ~/my-solana-wallet.json. On Windows, use %USERPROFILE%\my-solana-wallet.json instead of the ~ path.
Now tell the CLI to use this wallet:
solana config set --keypair ~/my-solana-wallet.json
Option B: Use an Existing Keypair File
If you already have a Solana keypair file (a .json file containing an array of numbers like [12,45,178,...]), point the CLI to it:
solana config set --keypair /path/to/your/keypair.json
Replace /path/to/your/keypair.json with the actual file path.
Verify Your Wallet Address
Check that the CLI is using the correct wallet:
solana address
This should print the same public address you see in your wallet app (Phantom, Solflare, etc.). If the address doesn't match, the keypair file doesn't correspond to the wallet you expected. Double-check your seed phrase and try again.
Also confirm your SOL balance to make sure everything is connected:
solana balance
You should see your current SOL balance. You need a tiny amount of SOL (at least 0.001 SOL) in your wallet to pay for transaction fees.
Step 5: Find Your Empty Token Accounts
Now let's see all the token accounts associated with your wallet:
spl-token accounts
This prints a table showing every token account in your wallet, including the token mint address and your balance. It looks something like this:
Token Balance
---------------------------------------------------------------
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v 0
Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB 0
7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj 15.5
DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 0
So11111111111111111111111111111111111111111112 0.42
The accounts with a balance of 0 are the ones you can close to recover your SOL. In this example, you have three empty accounts that are each holding ~0.00204 SOL in rent.
Make a note of the token mint addresses (the long strings on the left) for all accounts showing a 0 balance. You'll need them in the next step.
Important: Do not close the SOL account (the one with mint address So111...1112). That's your native SOL token account, also known as your wrapped SOL account. Closing it is fine only if its balance is 0 and you understand what it is.
Step 6: Close Empty Accounts One by One
For each empty token account, run the close command with that account's token mint address. For example, to close the empty USDC account from the list above:
spl-token close --address EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
If successful, you'll see output like:
Signature: 5Kz8...txSignatureHere
That means the account was closed and the ~0.00204 SOL rent deposit was returned to your wallet. You can verify by checking your balance:
solana balance
Your balance should have increased by approximately 0.00204 SOL (the exact rent amount for a standard token account).
What if You Get an Error?
Here are common errors and what they mean:
- "Account has a non-zero balance" — This account still has tokens in it. You cannot (and should not) close it. Either transfer the tokens first or skip this account.
- "Insufficient funds" — You don't have enough SOL to pay the network transaction fee. Deposit at least 0.001 SOL into your wallet.
- "Account not found" — The token mint address might be wrong. Double-check it against the output from
spl-token accounts. - "RPC request error" — The RPC endpoint is overloaded or unreachable. Wait a moment and try again, or switch to a different RPC endpoint (see Step 3).
Step 7: Repeat for All Empty Accounts
Go through each empty account from your list and run the close command. If you have 10 empty accounts, that's 10 separate commands:
spl-token close --address EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
spl-token close --address Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
spl-token close --address DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263
Each command sends a separate transaction to the blockchain. You'll pay ~0.000005 SOL per transaction in network fees — that's about $0.001 USD at $200/SOL.
Automate It with a Simple Script (Optional)
If you have many accounts to close, you can write a small bash script to handle them all. Create a file called close-all.sh:
#!/bin/bash
# Close all empty token accounts and recover SOL
# Get all token accounts with zero balance
spl-token accounts 2>/dev/null | while read -r line; do
# Extract mint address and balance
mint=$(echo "$line" | awk '{print $1}')
balance=$(echo "$line" | awk '{print $2}')
# Skip header lines and non-zero balances
if [[ "$balance" == "0" && ${#mint} -gt 30 ]]; then
echo "Closing account for mint: $mint"
spl-token close --address "$mint" 2>&1
echo "---"
fi
done
echo "Done! Check your balance:"
solana balance
Run it with:
bash close-all.sh
Windows users: This script requires bash. You can use Git Bash (installed with Git for Windows) or Windows Subsystem for Linux (WSL). Alternatively, just run each close command individually in PowerShell.
Step 8: Verify Your Recovery
After closing all empty accounts, check your final balance:
solana balance
Compare this to your balance before you started. The difference is the amount of SOL you recovered from rent deposits.
You can also verify that the empty accounts are gone:
spl-token accounts
The closed accounts should no longer appear in the list. Only accounts with non-zero balances should remain.
Step 9: Secure Your Keypair File
This step is critical. If you created a keypair file in Step 4, you need to handle it carefully:
- If you want to keep it: Store it in a secure location — an encrypted drive, a password manager, or offline storage. Never leave it in a publicly accessible folder.
- If you want to delete it: Since your wallet is still accessible via your seed phrase and wallet app, you can safely delete the keypair file:
rm ~/my-solana-wallet.json
On Windows:
del %USERPROFILE%\my-solana-wallet.json
Never upload your keypair file anywhere, email it, or store it in cloud storage like Google Drive or Dropbox without encryption.
CLI Recovery vs. Using SolRecover: A Comparison
You've just seen the full CLI process. Here's how it compares to using a tool like SolRecover:
| Solana CLI (Free) | SolRecover (1.9% Fee) | |
|---|---|---|
| Cost | Free (+ ~0.000005 SOL network fees) | 1.9% of recovered SOL |
| Setup time | 15–30 minutes | None (works in browser) |
| Technical skill | Requires terminal/CLI comfort | No technical skills needed |
| Private key handling | Keypair file stored on your computer | Keys never leave your wallet app |
| Accounts per transaction | 1 account per command | Up to 20 accounts per transaction |
| Automation | Manual (or write your own script) | Automatic scanning and batching |
| Time to recover (50 accounts) | 20–40 minutes | Under 1 minute |
| Error handling | You troubleshoot yourself | Handled automatically |
The CLI is ideal if you're comfortable with command-line tools, only have a few accounts to close, want to pay absolutely zero fees, or want to learn how Solana works under the hood.
SolRecover is ideal if you want to recover your SOL quickly without installing anything, have many accounts to close, or prefer not to handle keypair files directly on your machine.
Prefer to skip the command line? SolRecover finds and closes all your empty token accounts in a single click — no installation, no keypair files, no CLI commands.
Recover SOL InstantlyTroubleshooting Common Issues
"solana: command not found" After Installation
Your terminal doesn't know where the Solana CLI is installed. You need to add it to your PATH:
macOS/Linux: Open ~/.bashrc or ~/.zshrc in a text editor and add:
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
Save the file and run source ~/.bashrc (or source ~/.zshrc).
Windows: The installer should add it automatically. Try closing and reopening PowerShell. If it still doesn't work, search for "Environment Variables" in the Start menu and manually add the Solana install path to your system PATH.
"cargo: command not found"
You need to install Rust. See the instructions in Step 2 above. After installing, close and reopen your terminal.
Recovered Address Doesn't Match My Wallet
When importing via seed phrase, the derivation path matters. By default, solana-keygen recover uses a different derivation path than Phantom or Solflare. If the address doesn't match, try specifying the derivation path that Phantom uses:
solana-keygen recover 'prompt://?key=0/0' -o ~/my-solana-wallet.json
If you have multiple accounts in Phantom, the second account would use key=1/0, third key=2/0, and so on.
Transactions Failing with "Blockhash Not Found"
This usually means the RPC endpoint is congested. Wait 30 seconds and try again. If it persists, switch to a different RPC:
solana config set --url https://api.mainnet-beta.solana.com
Or use a dedicated RPC provider for better reliability.
"Account Is Not Closeable" or "Account Is Frozen"
Some token accounts have constraints that prevent closing:
- Frozen accounts can only be unfrozen by the token's freeze authority (the token creator). You can't close these.
- Token-2022 accounts with certain extensions may require special handling. See our guide on Token-2022 account cleanup.
Frequently Asked Questions
Is using the Solana CLI really free?
Yes. The only cost is the standard Solana network transaction fee (~0.000005 SOL per transaction), which is fractions of a cent. There are no service fees — you keep 100% of your recovered rent.
Is it safe to use the Solana CLI with my wallet?
The Solana CLI is the official tool built by Solana Labs. However, you are interacting directly with your private key or keypair file, so you need to be careful. Never share your keypair file or seed phrase, and make sure you download the CLI only from the official Solana documentation.
Can I accidentally close an account that still has tokens in it?
No. The spl-token close command will refuse to close any account that has a non-zero token balance. It will display an error and the account will remain untouched.
What if I have hundreds of empty accounts?
You can close them all using the CLI, but you'll need to run the close command for each account individually or write a script to automate it. For large numbers of accounts, a tool like SolRecover can batch-close up to 20 accounts per transaction and handle everything automatically.
Do I need to keep the Solana CLI installed after I'm done?
No. Once you've recovered your SOL, you can uninstall the CLI if you don't plan to use it again. Your recovered SOL stays in your wallet regardless.