ERC-165 Standard Interface Detection ,即检测合约是否实现接囗规范,使用函数标识(.selecor)进行检测。
可参考:ERC-165: Standard Interface Detection
接口实现:
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;
interface IERC165 {
/// @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);
}
合约代码示例:
// SPDX-License-Identifier: Apache-2.0
pragma solidity

ERC-165标准介绍了如何检测智能合约是否实现了特定接口,通过使用函数选择器进行查询。接口IERC165包含了一个supportsInterface函数,允许外部查看合约是否支持给定的接口ID。示例合约展示了如何在Solidity中实现这个标准,使用一个映射存储支持的接口信息。
最低0.47元/天 解锁文章
983

被折叠的 条评论
为什么被折叠?



