nft數藏系統開發功能(原始碼Demo)

Tg_StPv888發表於2023-02-28

  隨著區塊鏈的發展,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=“”;


  //返回”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售賣的時候,不需要


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70016646/viewspace-2937314/,如需轉載,請註明出處,否則將追究法律責任。

相關文章