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

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

随着区块链的发展,NFT也逐渐传入国内(数字藏品),大家都很好奇数藏APP是怎样开发出来的。今天就数藏APP开发过程中容易遇到的细节问题来简单说一下数藏APP开发过程中的注意点。  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=“”;  //返回”QmasWH…re2Ych?filename=metadata.json”  //如果使用服务器API返回则可以固定uri为”{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售卖的时候,不需要

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注