0

For preparing an Airdop, for example, I want to find all owners of a specific NFT contract at a set date (today is OK, just actual hodlers, not all previous owners).

In doing some digging most APIs seem to provide event listeners, so I would need to have a server out there constantly available and listening.

I can also see you could set up a subgraph on thegraph or other indexer and it would do the listening for you?

What are some other ways to do queries on the chain and filter for owners of a contract? It seems heavy duty to query/filter the whole blockchain.

Ideally I'm looking for JS/typescript code.

related questions and research below, really looking for advice on the best option here :D

dcsan
  • 121
  • 1
  • 5
  • 2
    I’m voting to close this question because the authur is just asking for someone to write code for them – natewelch_ Aug 26 '21 at 18:40
  • not really, i'm looking for advice on the best way to do it - with an indexer, or even adding a function to the contract to make it enumerable. I'm not sure of the trade offs from doing that - gas cost of keeping the data on-chain so its always available. its a common question, but actually quite deep in it's implications. There maybe a fn in ethers that handles this, but ERC721 doesn't afaik. – dcsan Aug 26 '21 at 20:56
  • "Ideally I'm looking for JS/typescript code" – natewelch_ Sep 07 '21 at 14:55
  • @dcsan This answer https://ethereum.stackexchange.com/a/64814 is exactly what you are looking for. You even commented on it, why didn't it work for you? – Ismael Nov 23 '21 at 14:37

1 Answers1

1

You can query the NFT id and iterate through it, 0 - n, calling owners.push(await tokenContract.ownerOf(i))

Ryan Sea
  • 638
  • 3
  • 20