Function Difference and Best Practice:
compress(amount, sourceTokenAccount, toAddress)compresses specific amounts from source to a specified recipient. Use for transfers and precise amounts.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. Here is how.
Get Started
Compress / Decompress Tokens
Installation
Installation
- npm
- yarn
- pnpm
Install packages in your working directory:Install the CLI globally:
- Localnet
- Devnet
In the code examples, use
createRpc() without arguments for localnet.Before we can compress or decompresss, we need:
- An SPL mint with an SPL interface. Create one for new mints via
createMint()or for existing mints viacreateSplInterface(). - For
compress()SPL tokens in an Associated Token Account, or - For
decompress()compressed token accounts with sufficient balance.
- Compress
- Decompress
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
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
Insufficient balance between decompress and compress
Insufficient balance between decompress and compress
Check your balances before operations:
Invalid owner
Invalid owner
Ensure the signer owns the tokens being decompressed/compressed:
Advanced Configuration
Compress to Different Owner
Compress to Different Owner
Compress tokens directly to someone else:
Batch Operations
Batch Operations
Compress multiple token accounts:
Decompress with Delegate Authority
Decompress with Delegate Authority