Ethereum 哪些信息包含NFT?

Ethereum 哪些信息包含NFT?,ethereum,solidity,smartcontracts,nft,Ethereum,Solidity,Smartcontracts,Nft,我正在使用solidity开发NFT市场,特别是在OpenZeppelin的ERC-721智能合约的基础上创建我自己的智能合约。我的NFT目前有5个属性(id、图像、描述、集合和图像)用于图像,我保存了ipfs在上传时开发的哈希 我的问题是在哪里保存所有这些属性,因为我有具有上述属性的Image struct,我将其添加到一个数组中,并使用数组中Image对象的id和创建者的地址创建NFT。我的意思是,我正在保存ERC-721合同之外的所有信息,所以我不太理解NFT是什么,因为属性不是来自NFT

我正在使用solidity开发NFT市场,特别是在OpenZeppelin的ERC-721智能合约的基础上创建我自己的智能合约。我的NFT目前有5个属性(id、图像、描述、集合和图像)用于图像,我保存了ipfs在上传时开发的哈希

我的问题是在哪里保存所有这些属性,因为我有具有上述属性的Image struct,我将其添加到一个数组中,并使用数组中Image对象的id和创建者的地址创建NFT。我的意思是,我正在保存ERC-721合同之外的所有信息,所以我不太理解NFT是什么,因为属性不是来自NFT,而是NFT是我的结构的一个属性

我是否正确实施了该标准,且ERC-721标准仅是NFT的必要功能,还是我将信息保存在不接触的地方

我的代码当前如下所示:

pragma solidity ^0.5.0;

import "./ERC721Full.sol";

contract NftShop is ERC721Full {
  string public name;
  Image[] public nft;
  uint public imageId = 0;
  mapping(uint => bool) public _nftExists;
  mapping(uint => Image) public images;

  struct Image {
    uint id;                  //id of the nft
    string hash;              //hash of the ipfs            
    string description;       //nft description
    string collection;        //what collection the nft bellongs
    address payable author;   //creator of the nft
  }

  //Event used when new Token is created
  event TokenCreated(
    uint id,
    string hash,
    string description,
    string collection,
    address payable author
  );

  constructor() public payable ERC721Full("NftShop", "NFTSHOP") {
    name = "NftShop";
  }

  //uploadImage to the blockchain and mint the nft.
  function uploadImage(string memory _imgHash, string memory _description, string memory _collection) public {
    // Make sure the image hash exists
    require(bytes(_imgHash).length > 0);
    // Make sure image description exists
    require(bytes(_description).length > 0);
    // Make sure collectionage exists
    require(bytes(_collection).length > 0);
    // Make sure uploader address exists
    require(msg.sender!=address(0));

    // Increment image id
    imageId ++;

    // Add Image to the contract
    images[imageId] = Image(imageId, _imgHash, _description, _collection, msg.sender);

    //Mint the token
    require(!_nftExists[imageId]);
    uint _id = nft.push(images[imageId]);
    _mint(msg.sender, _id);
    _nftExists[imageId] = true;

    // Trigger an event
    emit TokenCreated(imageId, _imgHash, _description, _collection, msg.sender);
  }
} 
如果有什么奇怪的地方,任何关于如何改进代码的建议都是受欢迎的

我希望这不是一个荒谬的问题,我从以太坊的世界开始


非常感谢。

是的,图像地址等信息存储在从ERC721继承的合同中。ERC721主要跟踪代币的所有权、铸造和转让

您可能需要考虑的一件事是令牌的唯一性。在您的示例中,可以存在许多具有相同图像和描述的令牌。 您可能希望通过存储_imgHash、_description、_集合的散列并要求它是唯一的来防止这种情况,这样就没有用户可以创建现有令牌的“副本”

比如:

keccak256(abi.encodePacked(_imgHash, _description, _collection))

另一个常用的标准是Opensea元数据标准,其中令牌URI存储在链上,元数据位于区块链之外

谢谢你的回答,我有一个类似的问题,关于存储_imgHash的散列、描述等。。。你认为这能适应一种“版税”的情况吗?在这种情况下,每一次后续销售都会给创作者带来一些收入?谢谢@DanielVieira和ERC721中的NFT有一个所有者。当它被出售时,它属于新主人。在版税场景中,您可能希望拥有多个所有者。每次销售都会产生对代币创建者的版税。这是可能的,但该功能也必须在继承自NFT(如ERC721)的合同中实现(或已经在另一个标准中)。非常感谢@ruff09,您是否涉猎过ERC-1155标准,显然它实现了版税标准,似乎很有趣。。。