This repository contains modular Solana scripts demonstrating how to utilize Token-2022 extensions using the @solana/spl-token JavaScript SDK. These extensions offer advanced token behaviors not available in the original SPL Token program.
Each script initializes a specific token extension or feature such as:
- ✅ Mint Close Authority
- 💸 Transfer Fee Configuration
- 🧊 Default Frozen Accounts
- 🔒 Immutable Owner (coming soon or handled in future updates)
⚠️ All scripts are tested on devnet and require a valid Solana wallet with some SOL balance.
Token-2022-Extensions/
├── mint-close-authority.js
├── transfer-fee.js
├── default-freeze.js
└── (optional) immutable-owner.js
-
Clone the repository
git clone https://github.com/<your-username>/Token-2022-Extensions.git cd Token-2022-Extensions
-
Install dependencies
npm install
-
Create a
.envfile Add your base58-encoded private key:PRIVATE_KEY=your_base58_secret_key -
Run any script Example:
node mint-close-authority.js
Adds the MintCloseAuthority extension to allow closing the mint in the future. This extension must be initialized before the mint itself.
-
Uses:
createInitializeMintCloseAuthorityInstructioncreateInitializeMintInstruction
Applies the TransferFeeConfig extension, enabling fee deduction on each transfer.
-
Parameters:
- Fee Basis Points:
50(0.5%) - Max Fee:
5_000(in base units, i.e., lamports)
- Fee Basis Points:
-
Uses:
createInitializeTransferFeeConfigInstructioncreateInitializeMintInstruction
Initializes the mint with DefaultAccountState set to Frozen, meaning all token accounts will be frozen by default until explicitly thawed.
-
Uses:
createInitializeDefaultAccountStateInstructioncreateInitializeMintInstruction
-
Optional Follow-up:
- You can later update the default state using
updateDefaultAccountState()if needed.
- You can later update the default state using
This section is reserved for implementing accounts with immutable ownership, where the owner cannot be changed after creation.
- Node.js
v16+ @solana/web3.js@solana/spl-token(ensure support for Token-2022 extensions)- Environment variable with a funded wallet
- These scripts are designed to demonstrate core concepts and are not production-hardened.
- Token-2022 is a separate program and requires explicit usage of
TOKEN_2022_PROGRAM_ID. - Don't forget to check for rent-exemption lamports using
getMinimumBalanceForRentExemption()for each extension.
Usama Hassan — @fighting45