1

I'm curious web3 developer. I've been researching several NFTs marketplace and I'm wondering how are they returning all the NFTs based on Contract Address.

For example, LOOKSRARE has an API that returns the NFTs of a given contractAddress, Opensea does the same but with their api url.

I'd like to know how is this possible? How can I build an API that goes through all the NFTs of a collection address and returned them. I thought of building a subgraph but not sure how useful it could be. Another approach I thought about was:

  • Getting the contract address
  • Reading the metadata / baseURI from the NFT contract and return it.

But not sure how to collect all of them. Is this really decentralized if its living in a database?

1 Answer 1

2

How can I build an API that goes through all the NFTs of a collection address and returned them.

I know this doesn't 100% directly answer your question, but I'd also recommend checking out the Alchemy NFT API:

https://docs.alchemy.com/alchemy/enhanced-apis/nft-api

For example, the getNFTsForCollection endpoint accomplishes your end goal.


For the other component of your question:

not sure how to collect all of them

Taking a step back, the reason you might want to use an API service like OpenSea, LooksRare, or Alchemy, is that it's actually pretty hard to build your own indexer, cache metadata, update metadata when it changes, and maintain a reliable uptime. It requires scanning the entire blockchain to monitor transfer events and transactions to get an accurate data set of who owns which NFT.

Hope this helps!

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.