Skip to main content
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

1

Compress / Decompress Tokens

Install packages in your working directory:
Install the CLI globally:
In the code examples, use createRpc() without arguments for localnet.
Before we can compress or decompresss, we need:
  • An SPL mint with a token pool for compression. This token pool can be created for new SPL mints via createMint() or added to existing SPL mints via createTokenPool().
  • For compress() SPL tokens in an Associated Token Account, or
  • For decompress() compressed token accounts with sufficient balance.
Make sure the SPL mint has a token pool for compression.
The script creates this token pool for you.
For development, you can create a new mint with token pool via createMint() or add a token pool to an existing mint via createTokenPool().

Troubleshooting

Check your balances before operations:
Ensure the signer owns the tokens being decompressed/compressed:

Advanced Configuration

Compress tokens directly to someone else:
Compress multiple token accounts:
Decompress tokens using delegate authority:

Next Steps

How to Compress Complete SPL Token Accounts