Amxx / subgraphs

53 stars 22 forks source link

NFT data stale? #4

Closed v0n0 closed 2 years ago

v0n0 commented 2 years ago

Hi, the eip721 subgraph seems to works fine, but for collections that do a reveal (which are most nowadays), the metadata is stale compared to what you can get from the contract.

Example, query NFTs from this contract:

{
  contract(id: "0x345974220a845ddeceed011e8e6106b59724b661") {
    asERC721 {
      tokens {
        identifier
        id
        uri
      }
    }
  }
}

Let's take 0x345974220a845ddeceed011e8e6106b59724b661, which has identifier 257 and uri ipfs://QmWckz84W5GPBjyoyCiDWsbwcGjUDWmBGPURmpZ9639tvm/257. If you follow it you will see there are no traits in the JSON.

If you go on Etherscan and read the contract, put the identifier as tokenId for the tokenURI function, you get another URL: ipfs://QmQCA6Hfr7357MrQskqsPmcBfGre8WDUUcH4qur15s4ELt/257. This has the full metadata.

Now the subgraph shows as fully synced, so maybe there's some black magic I'm not understanding? Is this a type of data that we cannot get from The Graph, because we have to run the contract each time?

Amxx commented 2 years ago

Hello @v0n0

This subgraph "discovers" ERC721 tokens when they are first transferred from address(0) to their initial owner. This is when data is fetch, including the URI.

Some contracts set the token URI at a later stage, but this is not part of the ERC721 standard. It would be possible to re-fetch the token URI everytime a token is transferred, but even that might not be satisfactory, (if the token is not transferred, data is not updated).

The simple solution would be to react to an "TokenURIUpdated" event ... but there is no such event defined in the 721 standard. This is definitely something the community should describe in an upcoming ERC ... but until then URI should be threated as "best effort"

coopbri commented 2 years ago

Hey @Amxx, thank you so much for your subgraphs, they are incredibly useful.

Given what you mentioned above, are you aware of any way to retrieve accurate token URIs (through The Graph or another data source) if they are retroactively changed after initial transfer, much like the up-to-date URIs viewable on Etherscan? I assume this is not straightforward since this functionality does not strictly abide by ERC-721 as you mentioned.

Amxx commented 2 years ago

I would go for asking the blockchain directly. Once you used thegraph to get the contract address and tokenId, you can just do a contract call.

If there are many you have multicall options.

coopbri commented 2 years ago

Sounds good, using The Graph for initial discovery and complementing with contract call.

Thanks a lot! :smile: