I'm now developing NFT backed loan site. Before, I've sent NFT to escrow account but now I need to lock NFT in user's wallet. Anyone know about locking nft in user's wallet, please help me.
1 Answer
For NFTs, you can use look into using the FreezeDelegatedAccount
and ThawDelegatedAccount
instructions from the Metaplex Token Metadata program.
https://github.com/metaplex-foundation/metaplex-program-library/issues/470#issuecomment-1132700105
The important thing to notice is when creating the Master Edition Account, both the "Mint Authority" and the "Freeze Authority" are transferred to the Master Edition PDA!
That means, no one can mint tokens or freeze accounts without going through the Token Metadata program.
The Token Metadata program has no instruction that allows you to mint tokens so no one can ever mint additional tokens (which ensures the non-fungibility of the token).
However, the Token Metadata program has one instruction that allows you to freeze the Token Account of the NFT. This is the FreezeDelegatedAccount instruction you are using.
The requirements of that FreezeDelegatedAccount instruction are a bit unique. It requires you to be the Delegated Account of the Token Account to freeze.
In order to be the Delegated Account of a Token Account, the owner of that Token Account must first use the Approve instruction from the SPL Token program. I am not 100% if it is possible for the Delegated address to be the same as the Owner's address but if not you could simply use another keypair you own.
Now that you have a Delegated account on that Token Account, you can use the FreezeDelegatedAccount instruction of the Token Metadata program to freeze that Token Account.
Note that you can also unfreeze it later using that same Delegated Account via the ThawDelegatedAccount instruction of the Token Metadata program.
-
-
As you know there might be many NFTs in user's wallet. And their freeze authority is not mine. then how can I get freeze authority? or how can I transfer freeze authority of NFT to me? Commented May 30, 2023 at 10:22
-
It doesn't work for pNFTs. Do you have an idea for pNFT how to implement staking? I think it can be implemented with lock and unlock of metaplex token metadata. But I can't figure out how it work with onchain program. github.com/metaplex-foundation/metaplex-program-library/blob/…– JulbhCommented Jun 16, 2023 at 8:36