Overview
Token-2022, also known as the Token Extensions Program, extends the functionality of the original SPL Token Program with additional features called “extensions”. These extensions enable advanced token functionality while maintaining backward compatibility with the core token operations. Anchor’sanchor-spl crate provides full support for Token-2022 extensions through:
- The
token_interfacemodule for basic operations - Extension-specific constraint syntax
- Helper functions for reading extension data
- CPI functions for extension-specific operations
What are Token Extensions?
Token extensions are optional features that can be added to mints and token accounts. Each extension adds specific functionality:- Metadata Pointer - Points to on-chain or off-chain metadata
- Token Metadata - Stores name, symbol, and URI directly in the mint
- Transfer Hook - Execute custom logic on every transfer
- Permanent Delegate - An authority that can always transfer tokens
- Transfer Fee - Charge fees on token transfers
- Interest Bearing - Tokens that accrue interest
- Non-Transferable - Soulbound tokens that cannot be transferred
- Mint Close Authority - Allows closing mint accounts
- Group Pointer & Member Pointer - Create token groups and members
- Confidential Transfers - Privacy-preserving transfers
- And more…
Using Token-2022 in Anchor
Thetoken_interface module works seamlessly with both token programs. To specifically use Token-2022:
Enabling Extensions on Mints
Extensions are enabled when creating a mint using theextensions constraint syntax:
Common Extensions
Metadata Pointer
The metadata pointer extension tells wallets and apps where to find token metadata.authority- Who can update the pointermetadata_address- Where the metadata is stored (often the mint itself)
Token Metadata
Store token metadata (name, symbol, URI) directly in the mint account.Transfer Hook
Execute custom program logic on every token transfer.- Enforce transfer restrictions
- Charge custom fees
- Update on-chain state on transfers
- Implement loyalty programs
Permanent Delegate
An authority that can always transfer tokens from any account, useful for:- Asset recovery
- Regulatory compliance
- Game mechanics
Mint Close Authority
Allows closing a mint account to recover rent, useful for temporary tokens.Transfer Fee
Charge a fee on every transfer, with fees accumulating in token accounts.Group Pointer & Member Pointer
Create relationships between tokens, useful for NFT collections.Reading Extension Data
Access extension data from mint accounts using helper functions:Complete Example: NFT with Metadata
Here’s a complete example creating an NFT with metadata using Token-2022:lib.rs
Validating Extension Constraints
You can validate extension configurations in your accounts:Calculating Mint Size with Extensions
Mints with extensions require more space. Use the helper function:Best Practices
- Use Token-2022 for new projects - More features, same core operations
- Initialize extensions before metadata - Some extensions must be set during mint creation
- Store metadata in the mint - Saves accounts and transaction complexity
- Validate extension configurations - Use constraints to ensure extensions are configured correctly
- Handle extension size - Mint accounts with extensions need more space
- Test extension combinations - Some extensions work well together, others may have interactions
Available Extensions
Full list of supported extensions:metadata_pointer- Points to metadata locationgroup_pointer- Points to token groupgroup_member_pointer- Points to group membertransfer_hook- Custom transfer logicpermanent_delegate- Always-authorized delegateclose_authority- Mint close authoritytransfer_fee_config- Transfer fees configurationtransfer_fee_amount- Per-account fee trackingmint_close_authority- Close mint authority (legacy)confidential_transfer- Privacy featuresdefault_account_state- New accounts default stateimmutable_owner- Cannot change ownermemo_transfer- Require memo on transfersnon_transferable- Soulbound tokensinterest_bearing_config- Interest-bearing tokenscpi_guard- Restrict CPI usage
Resources
Next Steps
- Token Basics - Review basic token operations
- Token Overview - Understand token concepts