- I would like to do the following on the front-end. I would like to have a list of "collections" we support and which user can select from. User connects to Phantom wallet and selects "collection A". Now I check all tokens in the user's wallet that belong to the "collection A" selected by the user. I was reading this thread https://forums.solana.com/t/possible-to-query-all-nft-addresses-in-a-specific-collection/3097/7 which basically says there is no easy way to query spl-tokens that belong to a specific collection because on solana there are no such things as collections.
How do you handle then releasing 1000 different (nft) tokens that are supposed to be under the same theme? They are collections in the end right? Also there was apparently a tool for it but the docs have been removed: what happened with https://docs.metaplex.com/mint-lists
Reading https://docs.metaplex.com/programs/token-metadata/ I learned that Metaplex attaches metadata to PDA of Mint Account. Could we maybe us that to identify a collection, if tokens have been release by Metaplex products
Thanks for your suggestions!
EDIT:
Apparently there is a solution for it already and collections are supported for months. ENTER: https://github.com/metaplex-foundation/js
This skd should support all nft related needs. Will test it and let others know if I managed to accomplish the task.
UPDATE 28.07.2022.
I had a look at the metaplex SDK and I can see that you have a method
metaplex.nfts().findByMint(mint).run();
Which is cool. So the part of getting the metadata could work.
However, the second part of the answer from @Mark Sackerberg:
and then filter by collection key in their metadata.
could be problematic.
Hey @Mark Sackerberg, I have deployed a test collection using metaplex on devnet.
- Mint address https://www.solaneyes.com/address/3fpk4L7tiEAbyqcuTVgTnhcpQ5PuG4rX6HXRRZu1gHhj
- Token address https://www.solaneyes.com/address/8nKu16RmMRM2ivEgKBtRBNsrBUsauckQ7Zb5JFUAdb6Z
- Metadata address https://www.solaneyes.com/address/ritvGTaMVdhhLTGBYeHw4LKoVrVNedmNTqmRWd6hct1
How can I now find all NFTs in the user's wallet that belong to this collection?
EDIT 29.08:
I found an answer.
If a collection has been deployed via metaplex AND it has attached collection metadata json config you can then query all NFTs that a user owns by doing:
const userNfts: (Nft | LazyNft)[] = await mx.nfts().findAllByOwner(userPublicKey).run()
Each nft that belongs to a collection, will have a collection property which is an object containing:
- Verified. More on the subject here
- Key (the mint address of the collection. You can treat it as CollectionId)
Then you need to filer those nfts based on that property using your language.