我有一个ERC721令牌,TokenURI被设置为IPFS链接。JSON包含有关NFT的元数据,如名称、颜色、图像等。
问题是我有一个允许更新TokenURI的函数,但是如何防止编辑'name‘字段?
还有其他方法只存储“名称”元数据吗?也许在ERC721合同的某个地方?
这是我的合同:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/token/ERC721/ERC721.sol";
contract SampleNFTContract is ERC721 {
constructor () public ERC721 ("NFTTest1", "NFT1"){
}
// mint nft
function createNFT(uint256 tokenID, string memory ipfsLink) external {
_safeMint(msg.sender, tokenID);
_setTokenURI(tokenID, ipfsLink);
}
// update ipfsLink
function updateURL(uint256 tokenID, string memory ipfsLink) external {
// check if owner
require(_isApprovedOrOwner(_msgSender(), tokenID), "Only owner can update");
_setTokenURI(tokenID, ipfsLink);
}
}发布于 2021-07-28 09:32:09
请参阅:https://eips.ethereum.org/EIPS/eip-721#simple-summary
/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x5b5e139f.
interface ERC721Metadata /* is ERC721 */ {
/// @notice A descriptive name for a collection of NFTs in this contract
function name() external view returns (string _name);
/// @notice An abbreviated name for NFTs in this contract
function symbol() external view returns (string _symbol);
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function tokenURI(uint256 _tokenId) external view returns (string);
}您可以对名称和符号使用额外的字段。
发布于 2021-07-28 14:23:30
据我所知,您希望有一种契约强制的方法来指定元数据将包括某个名称。
当然,如果契约允许任意URL链接到可以具有任何name集的任意JSON,那么您就无法实现这个目标。
这里有一些选择。
ERC721Metadata中,而是创建一个您单独管理的专有tokenName(uint256)函数。https://ethereum.stackexchange.com/questions/104204
复制相似问题