I need help with locking and unlocking SPL tokens. Does Solana or Metaplex provide any functionality for this, or do we need to work on a Rust program to achieve this?
2 Answers
Token 2022 has a couple extensions you might consider: https://spl.solana.com/token-2022/extensions
You could set a transfer fee of 100% which effectively locks the tokens.
You could set NonTransferable.
Or probably the best option is to add a Transfer Hook that checks with a very simple program to see if the token is locked or unlocked.
-
Thanks, but I need to lock and unlock specific amounts. For instance, if the total supply is 100 million, I want to lock 1 million initially, and after some time, lock an additional 1 million. Similarly, I want the ability to unlock different amount on different time.– BobzCommented Feb 1 at 6:03
-
That kind of granularity is gonna require a program handling the transfers or a program you call with a transfer hook. Commented Feb 1 at 18:55
-
Yep. But it depends with what you want to achieve.
Here is a simple instruction to lock an NonFungible token using umi
import { lockV1 } from '@metaplex-foundation/mpl-token-metadata'
await lockV1(umi, {
mint,
authority,
tokenStandard: TokenStandard.NonFungible,
}).sendAndConfirm(umi)
and unlock
import { unlockV1 } from '@metaplex-foundation/mpl-token-metadata'
await unlockV1(umi, {
mint,
authority,
tokenStandard: TokenStandard.NonFungible,
}).sendAndConfirm(umi)
To note is that the number of accounts you interact with will change with different standard. For example, the pNFT
standard introduces two a new way to lock asset with the Metadata delegate authority, where you transfer authority over the metadata account to a new authority.
Check out this section of the Metaplex docs https://developers.metaplex.com/token-metadata/delegates
-
basically, I need to lock fungible tokens. For example, if the total supply is 100 million, I want to initially lock 1 million. Later, I might lock an additional 1 million, and I also need the that to unlock different amounts at different times.– BobzCommented Feb 1 at 6:07