Common (Tokens)

Functionality that is common to multiple token standards.

  • ERC2981: NFT Royalties compatible with both ERC-721 and ERC-1155.

    • For ERC-721 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 ERC. Marketplaces are expected to voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.

supportsInterface(bytes4 interfaceId) → bool public

royaltyInfo(uint256 tokenId, uint256 salePrice) → address receiver, uint256 amount 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.

ERC-2981 allows setting the royalty to 100% of the price. In that case all the price would be sent to the royalty receiver and 0 tokens to the seller. Contracts dealing with royalty should consider empty transfers.

_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:

  • 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.

ERC2981InvalidDefaultRoyalty(uint256 numerator, uint256 denominator) error

The default royalty set is invalid (eg. (numerator / denominator) >= 1).

ERC2981InvalidDefaultRoyaltyReceiver(address receiver) error

The default royalty receiver is invalid.

ERC2981InvalidTokenRoyalty(uint256 tokenId, uint256 numerator, uint256 denominator) error

The royalty set for an specific tokenId is invalid (eg. (numerator / denominator) >= 1).

ERC2981InvalidTokenRoyaltyReceiver(uint256 tokenId, address receiver) error

The royalty receiver for tokenId is invalid.