ITPub博客

首页 > 区块链 > 区块链 > nft数藏系统开发功能(源码Demo)

nft数藏系统开发功能(源码Demo)

原创 区块链 作者:Tg_StPv888 时间:2023-02-28 10:55:04 0 删除 编辑

  随着区块链的发展,NFT也逐渐传入国内(数字藏品),大家都很好奇数藏APP是怎样开发出来的。今天就数藏APP开发过程中容易遇到的细节问题来简单说一下数藏APP开发过程中的注意点。数I8O藏2857系8624统


  The full name of the digital collection is Non-FungibleToken,abbreviated as NFT,which is a non-homogeneous token.The concept of NFT comes from foreign countries.It is a customized work using blockchain technology.The artwork forms a separate digital certificate.The authorization code is the information that protects copyright,and completes digital distribution,purchase,collection and use.The one-key digital collection of works is like a commodity,which is independent,indivisible,tamper-proof,verifiable and scarce.


  我们做的主要修改是增加一个Token ID到URL的映射。因为我们准备将NFT的图片和Metadata数据都放到IPFS上,所以增加一个Token ID到IPFS文件哈希的映射:


  contract ERC1155{


  mapping(uint256=>string)private _metadataHashes;


  string private _uriPrefix=“https://ipfs.infura.io/ipfs/”;


  //返回”https://ipfs.infura.io/ipfs/QmasWH…re2Ych?filename=metadata.json”


  //如果使用服务器API返回则可以固定uri为”https://api.example.com/metadata/{id}”


  function uri(uint256 id)public view returns(string memory){


  return _concat(_uriPrefix,_metadataHashes[id],“?filename=metadata.json”);


  }


  }


  第二个修改是增加一个mint()方法来铸造NFT:


  function mint(uint256 amount,string memory metadataHash)public returns(uint256){


  //如果只允许合约部署者铸造,加上判断:


  //require(msg.sender==owner,“Not contract owner”);


  nextTokenId++;


  uint256 tokenId=nextTokenId;


  _metadataHashes[tokenId]=metadataHash;


  _mint(msg.sender,tokenId,amount,“”);


  return tokenId;


  }


  最后一步是在isApprovedForAll()中判断下当前转移操作的发起者是不是OpenSea的代理合约:


  function isApprovedForAll(address account,address operator)public view returns(bool){


  //Whitelist OpenSea proxy contract for easy trading.


  ProxyRegistry proxyRegistry=ProxyRegistry(proxyRegistryAddress);


  if(address(proxyRegistry.proxies(account))==operator){


  return true;


  }


  return _operatorApprovals[account][operator];


  }


  这么做的目的是将来在OpenSea售卖的时候,不需要


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70016646/viewspace-2937314/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
专业区块项目开发团队:18028578624微電

注册时间:2022-04-13

  • 博文量
    158
  • 访问量
    95703