I would like to know if there is any method of identifying if an address is erc721 or 1155 without calling the differentiating functions on both.
3 Answers
According to the IEP-165 you can, I had a similar issue/question this article helped me.
Solidity get interface id and ERC165 by Nhan Cao
Hope this helps you out as well!
A detailed solution to your answer is given Stack Overflow. Please do have a look:
Answer can be divided into two cases:
- address supports ERC165 (implements
supportsInterface
), but it is not ERC721; - address does not support ERC165 (no
supportsInterface
implementation). As an example, it can be ERC20, any Smart Contract, EOA, etc.
First case: nftAddress.supportsInterface(type(IERC721).interfaceId);
returns false
. Thus your require
or if - else
handles it normally.
Second case: as supportsInterface
is not implemented at all, transaction fails without reason.