I want a user to access a certain function on my smart contract such that.

  1. I want them to select an NFT at the start of the game.
  2. The NFT must be from a collection that I set.
  3. the NFT allows the user to access a certain function on the smart contract.
  4. Once the game is over I want to blacklist an nft such that the user will not be able to use the same nft again.

I need suggestions as to how would I implement this in anchor


1 Answer 1


Assuming your NFTs has an onchain collection (Metaplex Certified Collection) and that you will implement an onchain program to do this (or you have an onchain program that do this) you need to provide the Mint account and the Metadata Account of the selected NFT in order to decode the Metadata on the instruction and check if the NFT belongs to a MCC that you allow to use your program instruction. I already answered a question on how to deserialize a Metadata account here.

If you want to blacklist the NFT to not be able to be used again, you will need to create an PDA for each NFT that you allow to play (you can avoid checking the Metadata account because you will have a PDA for each NFT that is able to play). This PDA will need an bool or u8 that allow you to check if the NFT was already used (will be false at the begining) and in your program instruction you have to check if the given Mint with it given PDA data was already used, if it was you can throw an error and if it wasn't you can play with it and set that bool to used at the end of the game

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.