109孤荷凌寒自学第0195天_区块链第109天NFT006
正文内容
【主要内容】
今天继续学习了解ntf的相关知识,并开始接触erc721合约标准。继续研究了erc165接口,共耗时16分钟。
(此外整理作笔记花费了约13分钟)
详细学习过程见文末学习过程屏幕录像。
【尝试写一个合约并调用之前预写的库】
由于今天的学习时间可能不足,于是就赶紧开始写一个合约,以调用之前的库,首先是进行了直接调用。
ERC165Checker. supportsERC165()
还成功地部署到了以太坊的测试网络上,不过,写在智能合约中的函数,却根本没有展示 出来 ,也不能被调用
没有出现我在智能合约中写的函数名称。
于是我就只好使用附着的方式继续研究——
现在代码如下:
```
pragma solidity ^0.4.24;
//来自于:https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/introspection/ERC165Checker.sol
/**
* @title ERC165Checker
* @dev Use `using ERC165Checker for address`; to include this library
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant InterfaceId_Invalid = 0xffffffff; //这个常量表示 另一个接口的标识 ,不知道是什么接口
bytes4 private constant InterfaceId_ERC165 = 0x01ffc9a7; //这个常量表示 erc165接口的标识
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
/**
* @notice 查询合同是否实现接口,还检查对ERC165的支持
* @param _address 表示的是要去检测的 合约 的地址 The address of the contract to query for support of an interface
* @param _interfaceId 表示要检测的合约里,是否有我们想要检测的 接口 的ID, The interface identifier, as specified in ERC-165
* @return true if the contract at _address indicates support of the interface with
* identifier _interfaceId, false otherwise
* @dev Interface identification is specified in ERC-165.
*/
//就是查看一个合约(使用合约地址address表明),是否支持某一个接口(使用接口ID表明,该接口是出了ERC165的supportsInterface(bytes4)即ID为0x01ffc9a7的其他接口)
function supportsInterface(address _address, bytes4 _interfaceId)
internal
view
returns (bool)
{
//第一个参数:_address 表示的是要去检测的 合约 的地址
//第二个参数:_interfaceId 表示要检测的合约里,是否有我们想要检测的 接口 的ID
// query support of both ERC165 as per the spec and support of _interfaceId //根据上面的过程,首先先查看是否支持ERC165,然后再使用supportsInterface(bytes4)去查看是否使用了接口_interfaceId //这里是&&,所以是以实现了ERC165为前提在检测接口的
//当你合约支持ERC165且支持ERC165的接口时,就说明你支持
return supportsERC165(_address) &&
supportsERC165Interface(_address, _interfaceId);
//这儿的return 语句
// 先检测 指定的合约 地址(_address)是不是支持erc165标准,是通过方法函数(自己这个库中的方法,在后面定义的)supportsERC165来实现的
// 因为使用的 && 逻辑运算,因此 表示 ,检查 到这个合约 是支持erc165标准的之后,再来 检查 这个合约 内部是否支持指定的 interfaceId 表示 的接口ID。
// 两者都检测成功,则返回true,只要其中一个没有检测成功,就返回false
}
```
不过由于时间关系,没有来得及部署测试,由此看来对库的使用,还需要进一步学习。
【同步语音笔记】
https://www.ximalaya.com/keji/19103006/354743523
【学习过程屏幕录屏】
https://www.bilibili.com/video/BV1Zt4y1S7PP/