for getting owner of a single NFT we use ownerOf(tokenId)
but how can I know who is owner the whole collection (owner of the contract) and then I can validate them to be able to set royalty fee to thier collection on NFT marketplace.
How NFT marketplaces like opensea do this?
And also how can I fetch new created collections in nft marketplace?
2 Answers
How to know the owner of a contract
As @Alexander Herranz has mentioned, it is not possible with current ERC-721 and ERC-1155 standards to do so in a simple request, you would need to scan the whole blockchain to identify the deployment transaction.
Furthermore, they do not emit events on their deployment, so one would need to search through all blocks until finding the deployment transaction.
How to know the creator of a contract to set their royalty fees
This is a tricky question because the account that deploys a contract that holds a collection (an ERC-721 or an ERC-1155) is not necessarily the creator of the art or the collection. The main point of NFT royalties is to reward creators for the value of their art.
Therefore, different marketplaces enforce different methods to accomplish this:
- Asking the creators to set the fees themselves in their centralized servers. Example from OpenSea.
- Scanning the contracts for specific implementations, such as the Operator Filter Registry from OpenSea.
- Scanning the contracts and their tokens for standard implementations, such as the ERC-2981 standard.
One would argue that the ERC-2981 standard is the most popular option among the community and the one that should stay over time, as it is the standard. Nonetheless, there is the problem of backwards compatibility, as many NFT contracts do not support it and, therefore, a centralized solution is often the most suitable for them.
How to fetch newly created collections
Similarly to the first question it is not possible to do this simply with current ERC-721 and ERC-1155 standards, as they do not emit events on their deployment.
Marketplaces, such as OpenSea, and block explorers, such as Etherscan, identify a new NFT collection when a transfer of a token has been performed, the first mint, and the token has metadata.
One way to replicate this would be to scan the blockchain for Transfer
(ERC-721), TransferSingle
, and TransferBatch
(ERC-1155) events and then trying to access their metadata.
You can check it in the block explorer like Etherscan
For example, for BoredApeYachtClub contract, deployed in Ethereum, creator address is: 0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03
You can see the deployment transaction of for BoredApeYachtClub NFT contract here (Apr-22-2021): https://etherscan.io/tx/0x22199329b0aa1aa68902a78e3b32ca327c872fab166c7a2838273de6ad383eba
If you are planning to do it programmatically, it do not seem to be possible: How to get the address of the contract deployer?