With ERC721, there's the 'ownerOf' function that takes a non-fungible token's id and returns the owner address, but ERC1155 doesn't officially require that a function like that be implemented. I made an ERC1155 contract through rarible.com, and I can't find a function implemented there either. Both rarible.com and Opensea.io marketplaces show the owners of ERC1155 NFTs, so I know it's possible, but I can't figure it out.
3 Answers
UPDATE: Now you can use the Moralis API /nft/{token_address}/owners
to get this directly.
This is quite difficult, as Anupam pointed out you would have to go through all the transfer events and save them to some sort of database. And this takes a lot of effort when you want to do it with a lot of big NFTs. I've never found an easy solution myself.
Full disclosure: I work at Moralis, and we've gotten a lot of these requests. And we're currently building this functionality, so hopefully in a few weeks you will be able to get this with only one line of code through the moralis SDK.
I'll edit this post once I know the full specification of this.
TheGraph is also an option, but it's a little bit cumbersome.
-
2Moralis is dead :(. What TheGraph subgraph are you talking about specfically? Also, how to do this during development on truffle? Aug 23, 2021 at 12:14
-
Moralis is not dead. But the API endpoint changed in the latest update to API version 2.0. The new endpoint for this is /nft/{address}/owners. I will update my original answer.– FilipAug 23, 2021 at 12:40
-
lol moralis is dead; It broke on mint day for 20 concurrent users... Dec 5, 2022 at 13:08
-
Please reach out to our suppor team if you need any assistance with your specific application.– FilipJan 9 at 14:54
If you want an ownerOf in ERC1155 youll have to implement it yourself.
rarible and opensea use indexing services like thegraph.com to keep track of transfers and who currently owns the token.
-
Is there a particular subgraph from thegraph.com that tracks the nft transfer? I'm not sure which particular subgraph to use Sep 3, 2021 at 15:44
-
@Dylan pointed it out correctly.
The openzeppelin implementation doesn't have any function for this.
One other way to do this is parsing events, as they are emitted on each transfer. This may get computationally expensive, so you can use TheGraph for indexing purposes.