Erc-1155

ERC 1155 的特許權使用費

  • March 1, 2022

您如何在正常的 ERC1155 契約中包含版稅?

像這樣的東西:


// Import 1155 token contract from Openzeppelin

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract NFTContract is ERC1155, Ownable {
   
   uint256 public constant ARTWORK = 0;
   uint256 public constant PHOTO = 1;
   
   constructor() ERC1155("https://wzh58eid3jnd.usemoralis.com/{id}.json") {
       _mint(msg.sender, ARTWORK, 1, "");
       _mint(msg.sender, PHOTO, 2, "");
   }
   function mint( address to, uint256 id, uint256 amount) public onlyOwner {
       _mint(to, id, amount, "");
   }
   function burn( address from, uint256 id, uint256 amount) public {
       require(msg.sender == from);
       _burn(from, id, amount);
   }
}``` 

簡短的回答:

  • 目前沒有一種單一的方法可以實現這一目標,並已被廣泛採用。
  • 添加您認為需要的平台的版稅功能(如 OpenSea)。下面提供的範例。

長答案

NFT 世界在版稅方面存在分歧。

正如您在此處看到的,OpenSea 似乎通過允許您在元數據中包含版稅資訊來實現脫鏈。

Rarible 有一個單獨的智能合約,稱為版稅系統資料庫,用於跟踪每個 NFT 的版稅。

各種網際網路資源建議將自定義程式碼添加到您的transferFrom()函式中。但是,我建議不要這樣做,如 EIP-2981 中所述

不可能知道哪些 NFT 轉移是銷售的結果,哪些僅僅是錢包移動或整合其 NFT。因此,我們不能強制每個傳遞函式,例如transferFrom()

值得慶幸的是,由於EIP-2981:NFT 版稅標準最近獲得批准,因此 NFT 領域缺乏一致性有望改變。現在還處於早期階段,但像Mintable這樣的一些市場已經實施了這一點,而且 OpenSea 也得到了公眾的支持

鑑於 EIP-2981 尚未得到更大市場的支持,我對您的建議是:

  1. 添加您認為需要的平台的版稅功能(如 OpenSea)
  2. 通過實施 EIP-2981 成為未來的證明。

下面是一個範例,說明如何根據您提供的資訊同時支持 EIP-2981 和 OpenSea。我已經從這個 repo複製了一些程式碼。

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import '@openzeppelin/contracts/utils/introspection/ERC165.sol';


interface IERC2981Royalties {
   
   function royaltyInfo(uint256 _tokenId, uint256 _value)
       external
       view
       returns (address _receiver, uint256 _royaltyAmount);
}

/// @dev This is a contract used to add ERC2981 support to ERC721 and 1155
abstract contract ERC2981Base is ERC165, IERC2981Royalties {
   struct RoyaltyInfo {
       address recipient;
       uint24 amount;
   }

   /// @inheritdoc ERC165
   function supportsInterface(bytes4 interfaceId)
       public
       view
       virtual
       override
       returns (bool)
   {
       return
           interfaceId == type(IERC2981Royalties).interfaceId ||
           super.supportsInterface(interfaceId);
   }
}

contract NFTContract is ERC1155, Ownable, ERC2981Base {
   
   uint256 public constant ARTWORK = 0;
   uint256 public constant PHOTO = 1;
   RoyaltyInfo private _royalties;
   
   constructor() ERC1155("https://wzh58eid3jnd.usemoralis.com/{id}.json") {
       _setRoyalties({YOUR ADDRESS HERE} , {ROYALTY PERCENTAGE IN BASIS POINTS});
       _mint(msg.sender, ARTWORK, 1, "");
       _mint(msg.sender, PHOTO, 2, "");
   }
   
   // This is just for OpenSea to find your metadata containing the royalties. 
   // This metadata is about the contract and not the individual NFTs
   function contractURI() public view returns (string memory) {
       return "https://metadata-url.com/my-metadata";
   }
   
   function mint( address to, uint256 id, uint256 amount) public onlyOwner {
       _mint(to, id, amount, "");
   }
   function burn( address from, uint256 id, uint256 amount) public {
       require(msg.sender == from);
       _burn(from, id, amount);
   }
   
   
   // Value is in basis points so 10000 = 100% , 100 = 1% etc
   function _setRoyalties(address recipient, uint256 value) internal {
       require(value <= 10000, 'ERC2981Royalties: Too high');
       _royalties = RoyaltyInfo(recipient, uint24(value));
   }


   function royaltyInfo(uint256, uint256 value)
       external
       view
       override
       returns (address receiver, uint256 royaltyAmount)
   {
       RoyaltyInfo memory royalties = _royalties;
       receiver = royalties.recipient;
       royaltyAmount = (value * royalties.amount) / 10000;
   }
   
   function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, ERC2981Base) returns (bool) {
       return super.supportsInterface(interfaceId);
   }
   
}

對於 OpenSea 的合約元數據,它可能看起來像這樣:

{
 "name": "NFT Contract",
 "description": "Really cool description about my art",
 "image": "https://openseacreatures.io/image.png", # Link to collection image
 "external_link": "https://openseacreatures.io", # Link to website
 "seller_fee_basis_points": 100, # Indicates a 1% seller fee.
 "fee_recipient": "0xA97F337c39cccE66adfeCB2BF99C1DdC54C2D721" # Where seller fees will be paid to.
}

完全同意這裡的第一個答案。最好的辦法是在您的契約中實施 EIP 2981,即使尚不支持,並且還向 OpenSea 提供您的版稅資訊。修改轉移函式可能會阻止交易所正確列出您的收藏。

注意:您可以在導入收藏後手動更新 OpenSea 中的版稅資訊,而不是將其包含在契約級 URI 中。如果您想保持一定的靈活性,而不是在 JSON 中永久設置收件人/級別,則相關。

除了版稅之外,OpenSea 還建議為簡化集合列​​表添加一些小功能,例如白名單、元交易、契約級 URI、令牌級 URI 覆蓋等。

這個 repo包含 ERC 1155 實施的所有智能合約,帶有 EIP 2981 版稅、OpenSea 建議的添加以及令牌/版本供應的獎勵硬上限(可以刪除)。

引用自:https://ethereum.stackexchange.com/questions/113793