Access controlling for specific NFT holders via a smart contract address

Is there a way to control accessibility of NFT holders with Moralis API? I have a racing game where NFT holders can participate to. But I want to allow its participation only for certain NFT holders. I don’t want to list all the NFTs, but rather I want to list a smart contract addresses to make it simpler. My idea is that NFT holders that associated to the smart contract have its access.

  • Is there a way to control accessibility of NFTs via smart contract?
  • How can I do that with Moralis?
  • Do I have to create my own smart contract to have this kind of logic?

Thanks in advance.

You can check with an api call if an address has nfts in a contract/connection with getNFTs. You can provider a list of token addresses to getNFTs

1 Like

If you want to do it via a smart contract then you will have to write that smart contract. If you want to do it in the backend then you can use the api

Thanks for the quick response.
It says on the document that Results are limited to 100 per page by default
Is the “page” mean to be each NFT? Can I retrieve1000 NFTs with the API?

You can retrieve 1000 nfts with 10 calls to the api by using pagination.

How can I restrict the accessibility by retrieving the list? Do I have to store all the addresses associated to the contract on my db, so I can use the list later to qualify? Otherwise, can I make use of Moralis Stream or something to achieve my mission?

one way to do it is to query the api or the blockchain when you want to check if a specific wallet address has an nft, you have to do this check in backend and you have to authenticate the user before that to make sure that he really owns that wallet address

you can look at nft gated examples in documentation

1 Like

How can I query a specific NFT that is not included in the first 100?
Is seems the search result is “none” if it’s not included in the first 100.

Is there a way to search all the 1000, and then return me the result?

How do you know the nft that you want to search for?
If you know it’s token id then it it easy.

Target NFT is detected via wallet address. If the user of the wallet purchased the NFT, I can easily find the NFT by knowing the wallet address.
I have successfully detected the matched NFT if it is listed in the 100 (via Get NFTs by contract).
But it fails if it’s not in the first 100.
So, my question is how can I include and search all the 1000 so that I can get correct search result in return.

You are using token_addresses parameter for that api endpoint? That way it will filter the results only for specific nft contracts