Given an address of a smart contract deployed to RSK, how can I tell if it is an NFT or not? Is there a "standard" way to do this?
1 回答
是的,如果智能合约为 NFT 实施众所周知的代币标准,那么有一个明确的方法可以做到这一点,这反过来又实施了众所周知的EIP165 标准接口定义。
(1) 最简单的方法是在 RSK 区块浏览器上查找地址。
如果智能合约地址为0x814eb350813c993df32044f862b800f91e0aaaf0
,则前往
https://explorer.rsk.co/address/0x814eb350813c993df32044f862b800f91e0aaaf0
在此页面上,您将看到一行“合约接口”,并且在此智能合约的情况下,显示ERC165 ERC721 ERC721Enumerable ERC721Metadata
。由于它包含ERC721
,我们知道它为不可替代的代币实现了该代币标准。
(2) 更程序化/ DIY的方式是使用EIP165标准中定义的函数,其接口复制如下:
interface ERC165 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
supportsInterface
如果调用return ,则无需过多讨论如何计算它的数学(阅读 EIP-165 标准以获取完整描述/解释) true
,那么您就知道该智能合约(声称)实现了该特定接口。
- 如果你想测试一个特定的智能合约是否实现了
“非同质化代币标准”:
- 称呼
supportsInterface(0x80ac58cd)
- 称呼
- 如果你想测试一个特定的智能合约是否实现了
“多代币标准”,这是目前第二流行的 NFT 标准:
- 称呼
supportsInterface(0xd9b67a26)
- 称呼
(请注意,虽然上述两个值都在各自的标准中进行了说明,但您也可能希望自己计算它们,并且 EIP-165 标准包含有关如何执行此操作的部分。)