'How to extend Solana spl_token program to add more functionality?
SPL_Token program contains lots of features, but I want to add more additional checks as per customer requirement. So I want to create custom spl_token program by extending original spl_token code
e.g. Lets say, I want to limit maximum token that can be transferred to any account in single transaction.
Also I want program_id of my custom program, to be used in assigned_program_id(as shown in solana explorer) of any account which is created.
Any help is appreciated.
Solution 1:[1]
If you want your custom program id to be used, you simply need to fork the SPL token code to add your changes.
The code for the base token program exists at https://github.com/solana-labs/solana-program-library/tree/master/token/program, and if you're making small changes, it'll be easiest to change and deploy that.
If the changes are more involved, you can add a new extension to the token-2022 program, found at https://github.com/solana-labs/solana-program-library/tree/master/token/program-2022
To add a new extension, you need to add the state and instructions required for the extension, and whether it exists on a mint or account. Here is a sample pull request to add an extension allowing for mints to be closed: https://github.com/solana-labs/solana-program-library/pull/2754
Note that wallets and dapps will not be compatible with another program id, and it will take some time before they can accept more than one token program id.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jon C |
