common.adoc 6.0 KB

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