transfer() function moves compressed tokens between accounts.
- SPL token transfers that update the existing account
- Compressed token transfers consume input accounts from the sender and create new output accounts for sender and recipient with updated balances.
function-transfer-compressed-tokens.ts
Full Code Example
1
Prerequisites
Make sure you have dependencies and developer environment set up!Prerequisites & Setup
Prerequisites & Setup
DependenciesDeveloper Environment
- npm
- yarn
- pnpm
- Localnet
- Devnet
By default, all guides use Localnet.
- npm
- yarn
- pnpm
2
Transfer Compressed Tokens
Run this script to transfer compressed tokens to a recipient!transfer-compressed-tokens.ts
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
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
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: