Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ERC2981Upgradeable

Inherits: Initializable, IERC2981, ERC165Upgradeable

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. IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the ERC. Marketplaces are expected to voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.

State Variables

ERC2981StorageLocation

bytes32 private constant ERC2981StorageLocation = 0xdaedc9ab023613a7caf35e703657e986ccfad7e3eb0af93a2853f8d65dd86b00;

Functions

_getERC2981Storage

function _getERC2981Storage() private pure returns (ERC2981Storage storage $);

__ERC2981_init

function __ERC2981_init() internal onlyInitializing;

__ERC2981_init_unchained

function __ERC2981_init_unchained() internal onlyInitializing;

supportsInterface

Query if a contract implements an interface

Interface identification is specified in ERC-165. This function uses less than 30,000 gas.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(IERC165, ERC165Upgradeable)
    returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<none>booltrue if the contract implements interfaceID and interfaceID is not 0xffffffff, false otherwise

royaltyInfo

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. NOTE: 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.

function royaltyInfo(uint256 tokenId, uint256 salePrice)
    public
    view
    virtual
    returns (address receiver, uint256 amount);

_feeDenominator

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.

function _feeDenominator() internal pure virtual returns (uint96);

_setDefaultRoyalty

*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.*
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual;

_deleteDefaultRoyalty

Removes default royalty information.

function _deleteDefaultRoyalty() internal virtual;

_setTokenRoyalty

*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.*
function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual;

_resetTokenRoyalty

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

function _resetTokenRoyalty(uint256 tokenId) internal virtual;

Errors

ERC2981InvalidDefaultRoyalty

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

error ERC2981InvalidDefaultRoyalty(uint256 numerator, uint256 denominator);

ERC2981InvalidDefaultRoyaltyReceiver

The default royalty receiver is invalid.

error ERC2981InvalidDefaultRoyaltyReceiver(address receiver);

ERC2981InvalidTokenRoyalty

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

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

ERC2981InvalidTokenRoyaltyReceiver

The royalty receiver for tokenId is invalid.

error ERC2981InvalidTokenRoyaltyReceiver(uint256 tokenId, address receiver);

Structs

RoyaltyInfo

struct RoyaltyInfo {
    address receiver;
    uint96 royaltyFraction;
}

ERC2981Storage

Note: storage-location: erc7201:openzeppelin.storage.ERC2981

struct ERC2981Storage {
    RoyaltyInfo _defaultRoyaltyInfo;
    mapping(uint256 tokenId => RoyaltyInfo) _tokenRoyaltyInfo;
}