common.adoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. :github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]
  2. :ERC2981: pass:normal[xref:token/common.adoc#ERC2981[`ERC2981`]]
  3. :ERC721Royalty: pass:normal[xref:token/ERC721.adoc#ERC721Royalty[`ERC721Royalty`]]
  4. :xref-ERC2981-supportsInterface-bytes4-: xref:token/common.adoc#ERC2981-supportsInterface-bytes4-
  5. :xref-ERC2981-royaltyInfo-uint256-uint256-: xref:token/common.adoc#ERC2981-royaltyInfo-uint256-uint256-
  6. :xref-ERC2981-_feeDenominator--: xref:token/common.adoc#ERC2981-_feeDenominator--
  7. :xref-ERC2981-_setDefaultRoyalty-address-uint96-: xref:token/common.adoc#ERC2981-_setDefaultRoyalty-address-uint96-
  8. :xref-ERC2981-_deleteDefaultRoyalty--: xref:token/common.adoc#ERC2981-_deleteDefaultRoyalty--
  9. :xref-ERC2981-_setTokenRoyalty-uint256-address-uint96-: xref:token/common.adoc#ERC2981-_setTokenRoyalty-uint256-address-uint96-
  10. :xref-ERC2981-_resetTokenRoyalty-uint256-: xref:token/common.adoc#ERC2981-_resetTokenRoyalty-uint256-
  11. :IERC165-supportsInterface: pass:normal[xref:utils.adoc#IERC165-supportsInterface-bytes4-[`IERC165.supportsInterface`]]
  12. = Common (Tokens)
  13. Functionality that is common to multiple token standards.
  14. * {ERC2981}: NFT Royalties compatible with both ERC721 and ERC1155.
  15. ** For ERC721 consider {ERC721Royalty} which clears the royalty information from storage on burn.
  16. == Contracts
  17. :RoyaltyInfo: pass:normal[xref:#ERC2981-RoyaltyInfo[`++RoyaltyInfo++`]]
  18. :_defaultRoyaltyInfo: pass:normal[xref:#ERC2981-_defaultRoyaltyInfo-struct-ERC2981-RoyaltyInfo[`++_defaultRoyaltyInfo++`]]
  19. :_tokenRoyaltyInfo: pass:normal[xref:#ERC2981-_tokenRoyaltyInfo-mapping-uint256----struct-ERC2981-RoyaltyInfo-[`++_tokenRoyaltyInfo++`]]
  20. :supportsInterface: pass:normal[xref:#ERC2981-supportsInterface-bytes4-[`++supportsInterface++`]]
  21. :royaltyInfo: pass:normal[xref:#ERC2981-royaltyInfo-uint256-uint256-[`++royaltyInfo++`]]
  22. :_feeDenominator: pass:normal[xref:#ERC2981-_feeDenominator--[`++_feeDenominator++`]]
  23. :_setDefaultRoyalty: pass:normal[xref:#ERC2981-_setDefaultRoyalty-address-uint96-[`++_setDefaultRoyalty++`]]
  24. :_deleteDefaultRoyalty: pass:normal[xref:#ERC2981-_deleteDefaultRoyalty--[`++_deleteDefaultRoyalty++`]]
  25. :_setTokenRoyalty: pass:normal[xref:#ERC2981-_setTokenRoyalty-uint256-address-uint96-[`++_setTokenRoyalty++`]]
  26. :_resetTokenRoyalty: pass:normal[xref:#ERC2981-_resetTokenRoyalty-uint256-[`++_resetTokenRoyalty++`]]
  27. [.contract]
  28. [[ERC2981]]
  29. === `++ERC2981++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.1/contracts/token/common/ERC2981.sol[{github-icon},role=heading-link]
  30. [.hljs-theme-light.nopadding]
  31. ```solidity
  32. import "@openzeppelin/contracts/token/common/ERC2981.sol";
  33. ```
  34. Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
  35. Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
  36. specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
  37. Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
  38. fee is specified in basis points by default.
  39. IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
  40. https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
  41. voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
  42. _Available since v4.5._
  43. [.contract-index]
  44. .Functions
  45. --
  46. * {xref-ERC2981-supportsInterface-bytes4-}[`++supportsInterface(interfaceId)++`]
  47. * {xref-ERC2981-royaltyInfo-uint256-uint256-}[`++royaltyInfo(_tokenId, _salePrice)++`]
  48. * {xref-ERC2981-_feeDenominator--}[`++_feeDenominator()++`]
  49. * {xref-ERC2981-_setDefaultRoyalty-address-uint96-}[`++_setDefaultRoyalty(receiver, feeNumerator)++`]
  50. * {xref-ERC2981-_deleteDefaultRoyalty--}[`++_deleteDefaultRoyalty()++`]
  51. * {xref-ERC2981-_setTokenRoyalty-uint256-address-uint96-}[`++_setTokenRoyalty(tokenId, receiver, feeNumerator)++`]
  52. * {xref-ERC2981-_resetTokenRoyalty-uint256-}[`++_resetTokenRoyalty(tokenId)++`]
  53. [.contract-subindex-inherited]
  54. .ERC165
  55. [.contract-subindex-inherited]
  56. .IERC2981
  57. [.contract-subindex-inherited]
  58. .IERC165
  59. --
  60. [.contract-item]
  61. [[ERC2981-supportsInterface-bytes4-]]
  62. ==== `[.contract-item-name]#++supportsInterface++#++(bytes4 interfaceId) → bool++` [.item-kind]#public#
  63. See {IERC165-supportsInterface}.
  64. [.contract-item]
  65. [[ERC2981-royaltyInfo-uint256-uint256-]]
  66. ==== `[.contract-item-name]#++royaltyInfo++#++(uint256 _tokenId, uint256 _salePrice) → address, uint256++` [.item-kind]#public#
  67. Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
  68. exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
  69. [.contract-item]
  70. [[ERC2981-_feeDenominator--]]
  71. ==== `[.contract-item-name]#++_feeDenominator++#++() → uint96++` [.item-kind]#internal#
  72. The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
  73. fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
  74. override.
  75. [.contract-item]
  76. [[ERC2981-_setDefaultRoyalty-address-uint96-]]
  77. ==== `[.contract-item-name]#++_setDefaultRoyalty++#++(address receiver, uint96 feeNumerator)++` [.item-kind]#internal#
  78. Sets the royalty information that all ids in this contract will default to.
  79. Requirements:
  80. - `receiver` cannot be the zero address.
  81. - `feeNumerator` cannot be greater than the fee denominator.
  82. [.contract-item]
  83. [[ERC2981-_deleteDefaultRoyalty--]]
  84. ==== `[.contract-item-name]#++_deleteDefaultRoyalty++#++()++` [.item-kind]#internal#
  85. Removes default royalty information.
  86. [.contract-item]
  87. [[ERC2981-_setTokenRoyalty-uint256-address-uint96-]]
  88. ==== `[.contract-item-name]#++_setTokenRoyalty++#++(uint256 tokenId, address receiver, uint96 feeNumerator)++` [.item-kind]#internal#
  89. Sets the royalty information for a specific token id, overriding the global default.
  90. Requirements:
  91. - `receiver` cannot be the zero address.
  92. - `feeNumerator` cannot be greater than the fee denominator.
  93. [.contract-item]
  94. [[ERC2981-_resetTokenRoyalty-uint256-]]
  95. ==== `[.contract-item-name]#++_resetTokenRoyalty++#++(uint256 tokenId)++` [.item-kind]#internal#
  96. Resets royalty information for the token id back to the global default.