Skip to main content
After compression, empty token accounts can now be closed to reclaim rent with closeAccount().
Function Difference and Best Practice:
  • compressSplTokenAccount(tokenAccount, remainingAmount) compresses the entire SPL token account balance minus optional remaining amount only to the same owner. Use to migrate complete token accounts with optional partial retention.
  • compress(amount, sourceTokenAccount, toAddress) compresses specific amounts from source to a specified recipient. Use for transfers and precise amounts. Here is how.

Get Started

1

Compress SPL Token Accounts

Install packages in your working directory:
Install the CLI globally:
In the code examples, use createRpc() without arguments for localnet.
The SPL mint must have an SPL Interface PDA for compression.
The script creates it for you.
For development, create a new mint with SPL interface via createMint() or add an SPL interface to an existing mint via createSplInterface().

Troubleshooting

The token account doesn’t have enough tokens for the operation.
The remainingAmount parameter exceeds the current account balance.

Advanced Configuration

Compress most tokens while leaving some in SPL format:
Compress several token accounts for the same mint:

Next Steps

How to Create a Mint Account with Interface PDA