transfer() function moves compressed tokens between accounts. Unlike regular SPL transfers that update existing account balances, compressed transfers consume input accounts from the sender and create new output accounts for sender and recipient with updated balances.
Before we can transfer compressed tokens, 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 viacreateTokenPool()., and - a source compressed token account with sufficient balance for the transfer amount.
Regular SPL token accounts can be compressed in the same transaction with
compress_or_decompress_amount, if needed.function-transfer-compressed-tokens.ts
Full Code Example
Prerequisites
Make sure you have dependencies and developer environment set up!Prerequisites & Setup
Prerequisites & Setup
Transferring Compressed Tokens
Run this script to transfer compressed tokens to a recipient!transfer-compressed-tokens.ts
Troubleshooting
Insufficient balance for transfer
Insufficient balance for transfer
The sender doesn’t have enough compressed tokens for the requested transfer amount.
Account limit exceeded
Account limit exceeded
The transfer requires more than 4 compressed accounts, which exceeds the transaction limit.
Advanced Configuration
Transfer to Multiple Recipients
Transfer to Multiple Recipients
Transfer to multiple recipients in separate transactions: