common.adoc 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. :xref-ERC2981-ERC2981InvalidDefaultRoyalty-uint256-uint256-: xref:token/common.adoc#ERC2981-ERC2981InvalidDefaultRoyalty-uint256-uint256-
  12. :xref-ERC2981-ERC2981InvalidDefaultRoyaltyReceiver-address-: xref:token/common.adoc#ERC2981-ERC2981InvalidDefaultRoyaltyReceiver-address-
  13. :xref-ERC2981-ERC2981InvalidTokenRoyalty-uint256-uint256-uint256-: xref:token/common.adoc#ERC2981-ERC2981InvalidTokenRoyalty-uint256-uint256-uint256-
  14. :xref-ERC2981-ERC2981InvalidTokenRoyaltyReceiver-uint256-address-: xref:token/common.adoc#ERC2981-ERC2981InvalidTokenRoyaltyReceiver-uint256-address-
  15. = Common (Tokens)
  16. Functionality that is common to multiple token standards.
  17. * {ERC2981}: NFT Royalties compatible with both ERC-721 and ERC-1155.
  18. ** For ERC-721 consider {ERC721Royalty} which clears the royalty information from storage on burn.
  19. == Contracts
  20. :RoyaltyInfo: pass:normal[xref:#ERC2981-RoyaltyInfo[`++RoyaltyInfo++`]]
  21. :ERC2981InvalidDefaultRoyalty: pass:normal[xref:#ERC2981-ERC2981InvalidDefaultRoyalty-uint256-uint256-[`++ERC2981InvalidDefaultRoyalty++`]]
  22. :ERC2981InvalidDefaultRoyaltyReceiver: pass:normal[xref:#ERC2981-ERC2981InvalidDefaultRoyaltyReceiver-address-[`++ERC2981InvalidDefaultRoyaltyReceiver++`]]
  23. :ERC2981InvalidTokenRoyalty: pass:normal[xref:#ERC2981-ERC2981InvalidTokenRoyalty-uint256-uint256-uint256-[`++ERC2981InvalidTokenRoyalty++`]]
  24. :ERC2981InvalidTokenRoyaltyReceiver: pass:normal[xref:#ERC2981-ERC2981InvalidTokenRoyaltyReceiver-uint256-address-[`++ERC2981InvalidTokenRoyaltyReceiver++`]]
  25. :supportsInterface: pass:normal[xref:#ERC2981-supportsInterface-bytes4-[`++supportsInterface++`]]
  26. :royaltyInfo: pass:normal[xref:#ERC2981-royaltyInfo-uint256-uint256-[`++royaltyInfo++`]]
  27. :_feeDenominator: pass:normal[xref:#ERC2981-_feeDenominator--[`++_feeDenominator++`]]
  28. :_setDefaultRoyalty: pass:normal[xref:#ERC2981-_setDefaultRoyalty-address-uint96-[`++_setDefaultRoyalty++`]]
  29. :_deleteDefaultRoyalty: pass:normal[xref:#ERC2981-_deleteDefaultRoyalty--[`++_deleteDefaultRoyalty++`]]
  30. :_setTokenRoyalty: pass:normal[xref:#ERC2981-_setTokenRoyalty-uint256-address-uint96-[`++_setTokenRoyalty++`]]
  31. :_resetTokenRoyalty: pass:normal[xref:#ERC2981-_resetTokenRoyalty-uint256-[`++_resetTokenRoyalty++`]]
  32. :supportsInterface-bytes4: pass:normal[xref:#ERC2981-supportsInterface-bytes4-[`++supportsInterface++`]]
  33. :royaltyInfo-uint256-uint256: pass:normal[xref:#ERC2981-royaltyInfo-uint256-uint256-[`++royaltyInfo++`]]
  34. :_feeDenominator-: pass:normal[xref:#ERC2981-_feeDenominator--[`++_feeDenominator++`]]
  35. :_setDefaultRoyalty-address-uint96: pass:normal[xref:#ERC2981-_setDefaultRoyalty-address-uint96-[`++_setDefaultRoyalty++`]]
  36. :_deleteDefaultRoyalty-: pass:normal[xref:#ERC2981-_deleteDefaultRoyalty--[`++_deleteDefaultRoyalty++`]]
  37. :_setTokenRoyalty-uint256-address-uint96: pass:normal[xref:#ERC2981-_setTokenRoyalty-uint256-address-uint96-[`++_setTokenRoyalty++`]]
  38. :_resetTokenRoyalty-uint256: pass:normal[xref:#ERC2981-_resetTokenRoyalty-uint256-[`++_resetTokenRoyalty++`]]
  39. [.contract]
  40. [[ERC2981]]
  41. === `++ERC2981++` link:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.4.0/contracts/token/common/ERC2981.sol[{github-icon},role=heading-link]
  42. [.hljs-theme-light.nopadding]
  43. ```solidity
  44. import "@openzeppelin/contracts/token/common/ERC2981.sol";
  45. ```
  46. Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
  47. Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
  48. specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
  49. Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
  50. fee is specified in basis points by default.
  51. IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
  52. https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the ERC. Marketplaces are expected to
  53. voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
  54. [.contract-index]
  55. .Functions
  56. --
  57. * {xref-ERC2981-supportsInterface-bytes4-}[`++supportsInterface(interfaceId)++`]
  58. * {xref-ERC2981-royaltyInfo-uint256-uint256-}[`++royaltyInfo(tokenId, salePrice)++`]
  59. * {xref-ERC2981-_feeDenominator--}[`++_feeDenominator()++`]
  60. * {xref-ERC2981-_setDefaultRoyalty-address-uint96-}[`++_setDefaultRoyalty(receiver, feeNumerator)++`]
  61. * {xref-ERC2981-_deleteDefaultRoyalty--}[`++_deleteDefaultRoyalty()++`]
  62. * {xref-ERC2981-_setTokenRoyalty-uint256-address-uint96-}[`++_setTokenRoyalty(tokenId, receiver, feeNumerator)++`]
  63. * {xref-ERC2981-_resetTokenRoyalty-uint256-}[`++_resetTokenRoyalty(tokenId)++`]
  64. [.contract-subindex-inherited]
  65. .ERC165
  66. [.contract-subindex-inherited]
  67. .IERC2981
  68. [.contract-subindex-inherited]
  69. .IERC165
  70. --
  71. [.contract-index]
  72. .Errors
  73. --
  74. * {xref-ERC2981-ERC2981InvalidDefaultRoyalty-uint256-uint256-}[`++ERC2981InvalidDefaultRoyalty(numerator, denominator)++`]
  75. * {xref-ERC2981-ERC2981InvalidDefaultRoyaltyReceiver-address-}[`++ERC2981InvalidDefaultRoyaltyReceiver(receiver)++`]
  76. * {xref-ERC2981-ERC2981InvalidTokenRoyalty-uint256-uint256-uint256-}[`++ERC2981InvalidTokenRoyalty(tokenId, numerator, denominator)++`]
  77. * {xref-ERC2981-ERC2981InvalidTokenRoyaltyReceiver-uint256-address-}[`++ERC2981InvalidTokenRoyaltyReceiver(tokenId, receiver)++`]
  78. [.contract-subindex-inherited]
  79. .ERC165
  80. [.contract-subindex-inherited]
  81. .IERC2981
  82. [.contract-subindex-inherited]
  83. .IERC165
  84. --
  85. [.contract-item]
  86. [[ERC2981-supportsInterface-bytes4-]]
  87. ==== `[.contract-item-name]#++supportsInterface++#++(bytes4 interfaceId) → bool++` [.item-kind]#public#
  88. Returns true if this contract implements the interface defined by
  89. `interfaceId`. See the corresponding
  90. https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
  91. to learn more about how these ids are created.
  92. This function call must use less than 30 000 gas.
  93. [.contract-item]
  94. [[ERC2981-royaltyInfo-uint256-uint256-]]
  95. ==== `[.contract-item-name]#++royaltyInfo++#++(uint256 tokenId, uint256 salePrice) → address receiver, uint256 amount++` [.item-kind]#public#
  96. Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
  97. exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
  98. NOTE: ERC-2981 allows setting the royalty to 100% of the price. In that case all the price would be sent to the
  99. royalty receiver and 0 tokens to the seller. Contracts dealing with royalty should consider empty transfers.
  100. [.contract-item]
  101. [[ERC2981-_feeDenominator--]]
  102. ==== `[.contract-item-name]#++_feeDenominator++#++() → uint96++` [.item-kind]#internal#
  103. The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
  104. fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
  105. override.
  106. [.contract-item]
  107. [[ERC2981-_setDefaultRoyalty-address-uint96-]]
  108. ==== `[.contract-item-name]#++_setDefaultRoyalty++#++(address receiver, uint96 feeNumerator)++` [.item-kind]#internal#
  109. Sets the royalty information that all ids in this contract will default to.
  110. Requirements:
  111. - `receiver` cannot be the zero address.
  112. - `feeNumerator` cannot be greater than the fee denominator.
  113. [.contract-item]
  114. [[ERC2981-_deleteDefaultRoyalty--]]
  115. ==== `[.contract-item-name]#++_deleteDefaultRoyalty++#++()++` [.item-kind]#internal#
  116. Removes default royalty information.
  117. [.contract-item]
  118. [[ERC2981-_setTokenRoyalty-uint256-address-uint96-]]
  119. ==== `[.contract-item-name]#++_setTokenRoyalty++#++(uint256 tokenId, address receiver, uint96 feeNumerator)++` [.item-kind]#internal#
  120. Sets the royalty information for a specific token id, overriding the global default.
  121. Requirements:
  122. - `receiver` cannot be the zero address.
  123. - `feeNumerator` cannot be greater than the fee denominator.
  124. [.contract-item]
  125. [[ERC2981-_resetTokenRoyalty-uint256-]]
  126. ==== `[.contract-item-name]#++_resetTokenRoyalty++#++(uint256 tokenId)++` [.item-kind]#internal#
  127. Resets royalty information for the token id back to the global default.
  128. [.contract-item]
  129. [[ERC2981-ERC2981InvalidDefaultRoyalty-uint256-uint256-]]
  130. ==== `[.contract-item-name]#++ERC2981InvalidDefaultRoyalty++#++(uint256 numerator, uint256 denominator)++` [.item-kind]#error#
  131. The default royalty set is invalid (eg. (numerator / denominator) >= 1).
  132. [.contract-item]
  133. [[ERC2981-ERC2981InvalidDefaultRoyaltyReceiver-address-]]
  134. ==== `[.contract-item-name]#++ERC2981InvalidDefaultRoyaltyReceiver++#++(address receiver)++` [.item-kind]#error#
  135. The default royalty receiver is invalid.
  136. [.contract-item]
  137. [[ERC2981-ERC2981InvalidTokenRoyalty-uint256-uint256-uint256-]]
  138. ==== `[.contract-item-name]#++ERC2981InvalidTokenRoyalty++#++(uint256 tokenId, uint256 numerator, uint256 denominator)++` [.item-kind]#error#
  139. The royalty set for a specific `tokenId` is invalid (eg. (numerator / denominator) >= 1).
  140. [.contract-item]
  141. [[ERC2981-ERC2981InvalidTokenRoyaltyReceiver-uint256-address-]]
  142. ==== `[.contract-item-name]#++ERC2981InvalidTokenRoyaltyReceiver++#++(uint256 tokenId, address receiver)++` [.item-kind]#error#
  143. The royalty receiver for `tokenId` is invalid.