4

I’m new to Ethereum, and I’m working on a side project I’m curious

  1. How can I discover every NFT on the Ethereum blockchain?

  2. Once I’ve identified the NFT, how do I fetch the metadata?

3
  • U sadly can’t do that in a “side” project , indexing the blockchain is a huge big problem and u need enormous resources. Take a look on how etherscan is doing it and look at the graph protocol, they try to achieve such a thing. By the way the term NFT is misleading better to look at the standard for nfts like erc721 and erc1155, cause you can only catch a thing if you know how it’s look like and that is way standards are awesome
    – Majd TL
    May 15, 2021 at 20:31
  • Projects like open sea try to trace some of the triggered events which are described in erc721, erc1155. However they do that for registered contracts and they don’t look at every contract the blockchain
    – Majd TL
    May 15, 2021 at 20:34
  • When u find an nft then you should look if it’s follow the standards erc721 or etc 1155 and in those standards is described what is the method in smart comments you need to call to find the meta data and how the meta data should look like
    – Majd TL
    May 15, 2021 at 20:41

2 Answers 2

4

First, you can't do this in a general way.

In my speech presented at NFT.nyc, I deployed on Ethereum Mainnet a smart contract which created 2^255 NFTs using the ERC-721 protocol. (Thank you, work sponsored by NFT.nyc and Chain 76. Link at http://nft.life.)

If you were planning to make a general database which held like (contract address, token ID, owner) then you would need more atoms than the universe has to store that in your database.


If you want to avoid "spam" projects like this as well as "fake" projects, and even "old versions" of projects (e.g. see how Su Squares re-deployed the project several times to new contract addresses)... then you are excluding a lot. Everybody I know who is working on that problem has decided to start with an allowlist and only check those tokens.


But, assume you really wanted a general solution, and you were willing to blocklist some NFTs which are impractical to index. And you only cared about ERC-721 (repeat similar approach for other standards). You would do this by one of these two approaches:

  1. Create a list of all contracts on the network (i.e. CODESIZE > 0) and interrogate them using ERC-165 for the ERC-721 interface ID.

  2. Play every block on the blockchain starting with when ERC-721 was finalized (June 22, 2018) and listen for the Transfer(address, address, uint256) event. Then filter that list using #1 above.


0xcert has created a tool which does exactly what you are describing and unfortunately it does require more than one beefy server to run. It is at https://github.com/0xcert/ethereum-scanner and is not publicly available. They may be willing to license the tool out or sell it. (I advise 0xcert as one of my clients.)

Other commercial options like OpenSea, Etherscan, Azure Blockchain (announced EOL), and Mathematica have a great API available. Everyone of them includes limitations and does not have open source.


For metadata, you just query every token for the tokenURI and record that information. Normalizing that data and making it useful would be one full time job. This is, again, why commercial providers like OpenSea will select only a relatively few token contracts to support.

1
0

As William was saying, there is no easy way to do this. You would have to build up your own database and scan through the blockchain for the mint events in ERC721 and ERC1155 contracts.

We stumbled upon this problem ourselves and we built a solution that you can use if you want. It doesn't quite get you the entire way, it will allow you to get all the NFTs owned by a specific address. So you could easily get all NFTs (and the metadata), from the current metamask user.

You can check it out at moralis.io, you can use the JS SDK to get all NFTs by a specific user. It's free to use.

const userEthNFTs = await Moralis.Web3.getNFTs();

Or you could use the REST API

GET /nft/wallet/{address}

Then you can get the metadata using

/nft/contract/{contract_address}/metadata

Huge disclaimer: I work at moralis :)

Your Answer

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

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