Common (Tokens)

Functionality that is common to multiple token standards.

  • ERC2981: NFT Royalties compatible with both ERC721 and ERC1155.

    • For ERC721 consider ERC721Royalty which clears the royalty information from storage on burn.

Contracts

ERC2981

import "@openzeppelin/contracts/token/common/ERC2981.sol";

Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.

Royalty information can be specified globally for all token ids via _setDefaultRoyalty, and/or individually for specific token ids via _setTokenRoyalty. The latter takes precedence over the first.

Royalty is specified as a fraction of sale price. _feeDenominator is overridable but defaults to 10000, meaning the fee is specified in basis points by default.

ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See Rationale in the EIP. Marketplaces are expected to voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.

Available since v4.5.

supportsInterface(bytes4 interfaceId) → bool public

royaltyInfo(uint256 _tokenId, uint256 _salePrice) → address, uint256 public

Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of exchange. The royalty amount is denominated and should be paid in that same unit of exchange.

_feeDenominator() → uint96 internal

The denominator with which to interpret the fee set in _setTokenRoyalty and _setDefaultRoyalty as a fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an override.

_setDefaultRoyalty(address receiver, uint96 feeNumerator) internal

Sets the royalty information that all ids in this contract will default to.

Requirements:

  • receiver cannot be the zero address.

  • feeNumerator cannot be greater than the fee denominator.

_deleteDefaultRoyalty() internal

Removes default royalty information.

_setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal

Sets the royalty information for a specific token id, overriding the global default.

Requirements:

  • tokenId must be already minted.

  • receiver cannot be the zero address.

  • feeNumerator cannot be greater than the fee denominator.

_resetTokenRoyalty(uint256 tokenId) internal

Resets royalty information for the token id back to the global default.