Skip to content

Instantly share code, notes, and snippets.

@JackBekket
Created November 4, 2021 15:24
Show Gist options
  • Save JackBekket/d1613e1aa91be56653f9cfc0b2141462 to your computer and use it in GitHub Desktop.
Save JackBekket/d1613e1aa91be56653f9cfc0b2141462 to your computer and use it in GitHub Desktop.
erc-165 interface id's for different OZ interfaces
pragma solidity ^0.8.0;
// SPDX-License-Identifier: MIT
import "../../../node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "../../../node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "../../../node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol";
contract InterfaceRegister {
bytes4 public _INTERFACE_ID_MSNFT;
bytes4 public _INTERFACE_ID_IERC721ENUMERABLE; // should be 0x780e9d63
bytes4 public _INTERFACE_ID_IERC721METADATA; // 0x5b5e139f
bytes4 public _INTERFACE_ID_IERC721; // 0x7aa5391d
function getInterfaceEnumerable() public view returns (bytes4) {
return _INTERFACE_ID_IERC721ENUMERABLE;
}
function getInterfaceMetadata() public view returns (bytes4) {
return _INTERFACE_ID_IERC721METADATA;
}
function getInterface721() public view returns (bytes4) {
return _INTERFACE_ID_IERC721;
}
function calculateIERC721Enumarable() public pure returns (bytes4) {
IERC721Enumerable i;
return i.totalSupply.selector ^ i.tokenOfOwnerByIndex.selector ^ i.tokenByIndex.selector;
}
function calculateIERC721Metadata() public pure returns (bytes4) {
IERC721Metadata i;
return i.name.selector ^ i.symbol.selector ^ i.tokenURI.selector;
}
function calculateIERC721() public pure returns (bytes4) {
IERC721 i;
return i.balanceOf.selector ^ i.ownerOf.selector ^ i.transferFrom.selector ^ i.approve.selector ^ i.getApproved.selector ^ i.setApprovalForAll.selector ^ i.isApprovedForAll.selector;
}
constructor() {
_INTERFACE_ID_IERC721ENUMERABLE = calculateIERC721Enumarable();
_INTERFACE_ID_IERC721METADATA = calculateIERC721Metadata();
_INTERFACE_ID_IERC721 = calculateIERC721();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment