【问题标题】:How can I tell if a smart contract on RSK is an NFT?如何判断 RSK 上的智能合约是否为 NFT?
【发布时间】:2021-08-28 12:58:06
【问题描述】:

给定部署到 RSK 的智能合约的地址,我如何判断它是否是 NFT?有没有“标准”的方式来做到这一点?

【问题讨论】:

    标签: solidity nft rsk


    【解决方案1】:

    是的,有一个明确的方法可以做到这一点, 如果智能合约实施了众所周知的 NFT 代币标准, 进而实现众所周知的EIP165 Standard Interface Definition

    (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);
    }
    

    无需过多地计算如何计算, (阅读 EIP-165 标准以获得完整的描述/解释) 如果调用supportsInterface 返回true,那么你知道 该智能合约(声称)实现了该特定接口。

    • 如果你想测试一个特定的智能合约是否实现了 "Non-Fungible Token Standard":
      • 致电supportsInterface(0x80ac58cd)
    • 如果你想测试一个特定的智能合约是否实现了 "Multi Token Standard", 这是目前第二流行的 NFT 标准:
      • 致电supportsInterface(0xd9b67a26)

    (请注意,虽然上述两个值都在各自的标准中进行了说明,但 您可能还希望自己计算它们,并且 EIP-165 标准包含有关如何执行此操作的部分。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 2022-09-25
      • 2021-04-24
      • 2021-11-23
      • 1970-01-01
      • 2022-11-12
      相关资源
      最近更新 更多