// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC165.sol";interfaceIERC4671isIERC165{/// Event emitted when a token `tokenId` is minted for `owner`
eventMinted(addressowner,uint256tokenId);/// Event emitted when token `tokenId` of `owner` is revoked
eventRevoked(addressowner,uint256tokenId);/// @notice Count all tokens assigned to an owner
/// @param owner Address for whom to query the balance
/// @return Number of tokens owned by `owner`
functionbalanceOf(addressowner)externalviewreturns(uint256);/// @notice Get owner of a token
/// @param tokenId Identifier of the token
/// @return Address of the owner of `tokenId`
functionownerOf(uint256tokenId)externalviewreturns(address);/// @notice Check if a token hasn't been revoked
/// @param tokenId Identifier of the token
/// @return True if the token is valid, false otherwise
functionisValid(uint256tokenId)externalviewreturns(bool);/// @notice Check if an address owns a valid token in the contract
/// @param owner Address for whom to check the ownership
/// @return True if `owner` has a valid token, false otherwise
functionhasValid(addressowner)externalviewreturns(bool);}
扩展
元数据
一个允许添加与每个代币相关联的元数据的接口。
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC4671.sol";interfaceIERC4671MetadataisIERC4671{/// @return Descriptive name of the tokens in this contract
functionname()externalviewreturns(stringmemory);/// @return An abbreviated name of the tokens in this contract
functionsymbol()externalviewreturns(stringmemory);/// @notice URI to query to get the token's metadata
/// @param tokenId Identifier of the token
/// @return URI for the token
functiontokenURI(uint256tokenId)externalviewreturns(stringmemory);}
枚举
一个允许枚举所有者的代币的接口。
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC4671.sol";interfaceIERC4671EnumerableisIERC4671{/// @return emittedCount Number of tokens emitted
functionemittedCount()externalviewreturns(uint256);/// @return holdersCount Number of token holders
functionholdersCount()externalviewreturns(uint256);/// @notice Get the tokenId of a token using its position in the owner's list
/// @param owner Address for whom to get the token
/// @param index Index of the token
/// @return tokenId of the token
functiontokenOfOwnerByIndex(addressowner,uint256index)externalviewreturns(uint256);/// @notice Get a tokenId by it's index, where 0 <= index < total()
/// @param index Index of the token
/// @return tokenId of the token
functiontokenByIndex(uint256index)externalviewreturns(uint256);}
委托
一个允许代币铸造的委托权限的接口。
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC4671.sol";interfaceIERC4671DelegateisIERC4671{/// @notice Grant one-time minting right to `operator` for `owner`
/// An allowed operator can call the function to transfer rights.
/// @param operator Address allowed to mint a token
/// @param owner Address for whom `operator` is allowed to mint a token
functiondelegate(addressoperator,addressowner)external;/// @notice Grant one-time minting right to a list of `operators` for a corresponding list of `owners`
/// An allowed operator can call the function to transfer rights.
/// @param operators Addresses allowed to mint
/// @param owners Addresses for whom `operators` are allowed to mint a token
functiondelegateBatch(address[]memoryoperators,address[]memoryowners)external;/// @notice Mint a token. Caller must have the right to mint for the owner.
/// @param owner Address for whom the token is minted
functionmint(addressowner)external;/// @notice Mint tokens to multiple addresses. Caller must have the right to mint for all owners.
/// @param owners Addresses for whom the tokens are minted
functionmintBatch(address[]memoryowners)external;/// @notice Get the issuer of a token
/// @param tokenId Identifier of the token
/// @return Address who minted `tokenId`
functionissuerOf(uint256tokenId)externalviewreturns(address);}
共识
一个允许基于预定义地址集的共识来铸造/撤销代币的接口。
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC4671.sol";interfaceIERC4671ConsensusisIERC4671{/// @notice Get voters addresses for this consensus contract
/// @return Addresses of the voters
functionvoters()externalviewreturns(address[]memory);/// @notice Cast a vote to mint a token for a specific address
/// @param owner Address for whom to mint the token
functionapproveMint(addressowner)external;/// @notice Cast a vote to revoke a specific token
/// @param tokenId Identifier of the token to revoke
functionapproveRevoke(uint256tokenId)external;}
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC4671.sol";interfaceIERC4671PullisIERC4671{/// @notice Pull a token from the owner wallet to the caller's wallet
/// @param tokenId Identifier of the token to transfer
/// @param owner Address that owns tokenId
/// @param signature Signed data (tokenId, owner, recipient) by the owner of the token
functionpull(uint256tokenId,addressowner,bytesmemorysignature)external;}
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./IERC165.sol";interfaceIERC4671StoreisIERC165{// Event emitted when a IERC4671Enumerable contract is added to the owner's records
eventAdded(addressowner,addresstoken);// Event emitted when a IERC4671Enumerable contract is removed from the owner's records
eventRemoved(addressowner,addresstoken);/// @notice Add a IERC4671Enumerable contract address to the caller's record
/// @param token Address of the IERC4671Enumerable contract to add
functionadd(addresstoken)external;/// @notice Remove a IERC4671Enumerable contract from the caller's record
/// @param token Address of the IERC4671Enumerable contract to remove
functionremove(addresstoken)external;/// @notice Get all the IERC4671Enumerable contracts for a given owner
/// @param owner Address for which to retrieve the IERC4671Enumerable contracts
functionget(addressowner)externalviewreturns(address[]memory);}
// SPDX-License-Identifier: MIT
pragmasolidity^0.8.0;import"./ERC4671.sol";contractEIPCreatorBadgeisERC4671{constructor()ERC4671("EIP Creator Badge","EIP"){}functiongiveThatManABadge(addressowner)external{require(_isCreator(),"You must be the contract creator");_mint(owner);}function_baseURI()internalpureoverridereturns(stringmemory){return"https://eips.ethereum.org/ntt/";}}
这可能是一个由 Ethereum 基金会管理的合约,它允许他们向 EIP 创建者交付代币。
安全注意事项
一个安全方面与 tokenURI 方法有关,该方法返回链接到代币的元数据。由于该标准代表着本质上属于个人的财产,因此用户可能希望在某些情况下对数据进行加密,例如国民身份证。此外,合约创建者有责任确保此方法返回的 URI 始终可用。