给定部署到 RSK 的智能合约的地址,我如何判断它是否是 NFT?有没有“标准”的方法来做到这一点?
是的,如果智能合约为 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);
}
Run Code Online (Sandbox Code Playgroud)
无需过多计算如何计算(阅读 EIP-165 标准以获取完整描述/解释),如果调用 supportsInterface返回true,那么您就会知道该智能合约(声称)实现了该特定接口。
supportsInterface(0x80ac58cd)supportsInterface(0xd9b67a26)(请注意,虽然上述两个值都在各自的标准中说明,但您也可能希望自己计算它们,并且 EIP-165 标准包含有关如何执行此操作的部分。)
| 归档时间: |
|
| 查看次数: |
82 次 |
| 最近记录: |