mergeTokenAccounts() function consolidates multiple compressed accounts of the same mint into a single compressed account.
The function
- consumes multiple compressed token accounts (up to 8 accounts), and
- creates a single output compressed token account with combined balance for the owner.
Get Started
1
Merge Compressed Accounts
Installation
Installation
- npm
- yarn
- pnpm
- SDK 2.0 (token-interface)
Install packages in your working directory:Install the CLI globally:
- Localnet
- Devnet
In the code examples, use
createRpc() without arguments for localnet.Before we merge compressed accounts, we need
- Multiple compressed token accounts of the same mint owned by the same wallet, and
- 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().
Troubleshooting
No compressed token accounts found
No compressed token accounts found
The owner has no compressed token accounts for the specified mint:
Advanced Configuration
Conditional Merging
Conditional Merging
Merge Multiple Mints
Merge Multiple Mints