首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止更新ERC721元数据

防止更新ERC721元数据
EN

Ethereum用户
提问于 2021-07-28 08:27:51
回答 2查看 591关注 0票数 0

我有一个ERC721令牌,TokenURI被设置为IPFS链接。JSON包含有关NFT的元数据,如名称、颜色、图像等。

问题是我有一个允许更新TokenURI的函数,但是如何防止编辑'name‘字段?

还有其他方法只存储“名称”元数据吗?也许在ERC721合同的某个地方?

这是我的合同:

代码语言:javascript
复制
// 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);

}

}
EN

回答 2

Ethereum用户

发布于 2021-07-28 09:32:09

请参阅:https://eips.ethereum.org/EIPS/eip-721#simple-summary

代码语言:javascript
复制
/// @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);
}

您可以对名称和符号使用额外的字段。

票数 0
EN

Ethereum用户

发布于 2021-07-28 14:23:30

据我所知,您希望有一种契约强制的方法来指定元数据将包括某个名称。

当然,如果契约允许任意URL链接到可以具有任何name集的任意JSON,那么您就无法实现这个目标。

这里有一些选择。

  1. 放弃吧。不要将名称放在ERC721Metadata中,而是创建一个您单独管理的专有tokenName(uint256)函数。
  2. 使用ERC2477 (草案)。这允许您对元数据进行某种控制,以确保名称是您想要的名称。请注意,这将要求您在链上实现零知识证明或JSON解析器,以验证新的元数据。
  3. 使用0xcertFramework。0xcert框架专门为ERC-721令牌提供元数据完整性,它使用了一种与用例兼容的不同的散列技术(Merkle )。但它要求跨元数据版本使用相同的架构。
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/104204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档