简体   繁体   中英

How can I tell if a smart contract on RSK is an NFT?

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?

Yes there is a definitive way to do this, if the smart contracts implement well-known token standards for NFTs, which in turn implement the well-known EIP165 Standard Interface Definition .

(1) The easiest way to do this is to simply look up the address on the RSK block explorer.

If the smart contract address is 0x814eb350813c993df32044f862b800f91e0aaaf0 , then go to https://explorer.rsk.co/address/0x814eb350813c993df32044f862b800f91e0aaaf0

On this page, you will see a row for "Contract Interfaces", and in the case of this smart contract, displays ERC165 ERC721 ERC721Enumerable ERC721Metadata . Since this contains ERC721 , we know that it implements that token standard for non-fungible tokens.

(2) The more programmatic/ DIY way to do this is to use the function defined in the EIP165 standard, whose interface is copied below:

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

Without going too much into the math of how this is calculated, (read the EIP-165 standard for the full description/ explanation) if invoking supportsInterface returns true , then you know that that this smart contracts (claims to) implement that particular interface.

  • If you wish to test if a particular smart contract implements the "Non-Fungible Token Standard" :
    • call supportsInterface(0x80ac58cd)
  • If you wish to test if a particular smart contract implements the "Multi Token Standard" , which is presently the 2nd most popular NFT standard:
    • call supportsInterface(0xd9b67a26)

(Note that while both of the above values are stated in their respective standards, you may also wish to calculate them yourself, and the EIP-165 standard includes section on how to do this.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM