Skip to main content
The 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 via createTokenPool()., 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!

Dependencies

Alternatives:

Developer Environment

By default, this guide uses Localnet.
Alternative: Using DevnetFollow these steps to create an RPC Connection. Replace <your_api_key> with your API key before running.
Get your API Key here, if you don’t have one yet.

Transferring Compressed Tokens

Run this script to transfer compressed tokens to a recipient!
transfer-compressed-tokens.ts

Troubleshooting

The sender doesn’t have enough compressed tokens for the requested transfer amount.
The transfer requires more than 4 compressed accounts, which exceeds the transaction limit.

Advanced Configuration

Transfer to multiple recipients in separate transactions:
Transfer tokens using delegate authority:

Next Steps

Learn how compress and decompress SPL Tokens.