1
2
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

定义

非同质化代币(也称为契约)的标准接口。

每个符合 ERC-721 的合约都必须实现ERC721ERC165接口

  • 它更大的想象空间在于将物理世界的资产映射到区块链上。

  • 谜恋猫是第一个实现了ERC721 标准的去中心化应用

  • ERC20代币是可置换的,且可细分为N份(1 = 10 * 0.1), 而ERC721的Token最小的单位为1,无法再分割。

如果同一个集合的两个物品具有不同的特征,这两个物品是非同质的,而同质是某个部分或数量可以被另一个同等部分或数量所代替。

钱包接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// @dev Note: the ERC-165 identifier for this interface is 0x150b7a02.
interface ERC721TokenReceiver {
/// @notice Handle the receipt of an NFT
/// @dev The ERC721 smart contract calls this function on the recipient
/// after a `transfer`. This function MAY throw to revert and reject the
/// transfer. Return of other than the magic value MUST result in the
/// transaction being reverted.
/// Note: the contract address is always the message sender.
/// @param _operator The address which called `safeTransferFrom` function
/// @param _from The address which previously owned the token
/// @param _tokenId The NFT identifier which is being transferred
/// @param _data Additional data with no specified format
/// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
/// unless throwing
function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4);

参考:https://learnblockchain.cn/article/33

实战

基于OpenZeppelin的ERC721智能合约MyERC721Token

参考https://learnblockchain.cn/article/14779