Skip to main content

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’s anchor-spl crate provides full support for Token-2022 extensions through:
  • The token_interface module 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

The token_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 the extensions constraint syntax:

Common Extensions

Metadata Pointer

The metadata pointer extension tells wallets and apps where to find token metadata.
Key fields:
  • authority - Who can update the pointer
  • metadata_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.
Use cases:
  • 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

  1. Use Token-2022 for new projects - More features, same core operations
  2. Initialize extensions before metadata - Some extensions must be set during mint creation
  3. Store metadata in the mint - Saves accounts and transaction complexity
  4. Validate extension configurations - Use constraints to ensure extensions are configured correctly
  5. Handle extension size - Mint accounts with extensions need more space
  6. Test extension combinations - Some extensions work well together, others may have interactions

Available Extensions

Full list of supported extensions:
  • metadata_pointer - Points to metadata location
  • group_pointer - Points to token group
  • group_member_pointer - Points to group member
  • transfer_hook - Custom transfer logic
  • permanent_delegate - Always-authorized delegate
  • close_authority - Mint close authority
  • transfer_fee_config - Transfer fees configuration
  • transfer_fee_amount - Per-account fee tracking
  • mint_close_authority - Close mint authority (legacy)
  • confidential_transfer - Privacy features
  • default_account_state - New accounts default state
  • immutable_owner - Cannot change owner
  • memo_transfer - Require memo on transfers
  • non_transferable - Soulbound tokens
  • interest_bearing_config - Interest-bearing tokens
  • cpi_guard - Restrict CPI usage

Resources

Next Steps