Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-2981 provides a common way for NFT contracts to communicate royalty information to marketplaces. This article examines its design and whether it can actually enforce payments on secondary sales.

The explanation is based on the following proposal.

Background

Creators commonly sell NFTs through marketplaces. Whether they receive royalties on subsequent sales has historically depended on the marketplace's policies.

Suppose a creator issues an NFT and sells it through a marketplace. A buyer purchases the work, and the creator receives the proceeds from the initial sale.

Initial NFT sale

The buyer may later sell that NFT to someone else through a marketplace. This is a secondary sale.

Secondary NFT sale

An NFT royalty is a portion of the secondary sale proceeds allocated to a creator or another designated recipient. Royalties can give creators continuing revenue, but they also reduce the proceeds retained by resellers.

If a marketplace allows royalties to be set to zero, sellers may prefer it over a marketplace that collects royalties. Creators then lose the anticipated secondary-sale revenue.

This problem motivated discussions about representing royalty information directly in smart contracts. ERC-2981 emerged as a common interface for that purpose.

Summary

ERC-2981 standardizes the retrieval of NFT royalty information. It enables compatible marketplaces to obtain a royalty recipient and amount using a consistent interface.

A technical standard provides a common specification that independent projects can implement. Shared interfaces improve interoperability and reduce the need for project-specific integrations.

Motivation

NFT marketplaces historically maintained their own royalty configurations, often without sharing them with other marketplaces.

ERC-2981 allows marketplaces to query standardized royalty information directly from compatible contracts. It focuses on ERC-721 and ERC-1155 NFTs but can also be used by other contract types.

A marketplace that ignores the interface may still facilitate a sale without paying royalties. The standard aims to make voluntary support practical across the ecosystem, rather than force every marketplace to collect payments.

Continuing royalty revenue can help artists, creators, and projects sustain their work. Fragmented royalty configurations make it difficult for creators to rely on that revenue.

The original proposal illustrates the problem through a conversation between an artist and a marketplace: the marketplace supports royalties on its own platform but cannot enforce them elsewhere and does not share the creator's royalty settings with competing platforms.

Specification

ERC-2981 defines an interface for obtaining royalty information. A marketplace supporting the standard must pay royalties in the same unit as the sale price passed to royaltyInfo. For example, a sale denominated in ETH requires an ETH royalty, while a sale denominated in USDC requires a USDC royalty.

The royalty amount must therefore be calculated as a percentage of the supplied sale price.

Royalty calculation based on the sale price

The royaltyInfo function does not know which currency the sale price represents. Its returned amount must use the same unit as the supplied price.

The percentage must be independent of the numerical sale price. A 10% royalty, for example, applies the same percentage regardless of whether the sale price is 100 or 1,000 units. For a price of 999 units, an implementation may round the 99.9-unit royalty up to 100 or down to 99.

The percentage may vary according to predictable variables, such as the token ID or the number of previous transfers.

When royaltyAmount is zero, the marketplace should not submit an unnecessary royalty payment transaction.

The interface enables standardized calculation and discovery, not automatic enforcement.

For background on interfaces, see:

https://chaldene.net/erc721#st-toc-h-5

javascript
pragma solidity ^0.6.0;
import "./IERC165.sol";

interface IERC2981 is IERC165 {
    function royaltyInfo(
        uint256 _tokenId,
        uint256 _salePrice
    ) external view returns (
        address receiver,
        uint256 royaltyAmount
    );
}

interface IERC165 {
    function supportsInterface(bytes4 interfaceID) external view returns (bool);
}

royaltyInfo

Returns royalty information for a token given its sale price.

Parameters

  • _tokenId: Identifier of the NFT.
  • _salePrice: Sale price of that NFT.

Return values

  • receiver: Address designated to receive the royalty.
  • royaltyAmount: Royalty amount calculated from the supplied sale price.

ERC-721 integration example

javascript
constructor (string memory name, string memory symbol, string memory baseURI) {
    _name = name;
    _symbol = symbol;
    _setBaseURI(baseURI);
    _registerInterface(_INTERFACE_ID_ERC721);
    _registerInterface(_INTERFACE_ID_ERC721_METADATA);
    _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
    _registerInterface(_INTERFACE_ID_ERC2981);
}

The historical ERC-721 constructor registers the ERC-2981 interface identifier alongside the existing ERC-721 interfaces. A constructor runs during contract deployment. Registering an interface identifier announces support; the contract must also actually implement the corresponding functions.

javascript
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;

function checkRoyalties(address _contract) internal returns (bool) {
    (bool success) = IERC165(_contract).supportsInterface(_INTERFACE_ID_ERC2981);
    return success;
 }

This example queries ERC-165 to determine whether the NFT contract reports support for ERC-2981 using interface ID 0x2a55205a.

Rationale

Optional royalty payments

A token transfer does not necessarily represent a sale. It may be a gift or a movement between wallets controlled by the same person.

Requiring royalties for every transfer would incorrectly charge for operations that have no sale price. ERC-2981 therefore does not require payment logic inside every token-transfer function. The settlement mechanism remains the responsibility of the marketplace or other integration.

A single royalty recipient

The proposal returns one recipient address without specifying how the recipient distributes the funds.

Splitting fees among several parties, collecting taxes, and maintaining accounting records can require application-specific logic. A recipient can be a contract that implements those additional arrangements.

Calculating the royalty percentage

A royalty percentage may depend on predictable variables. It should not depend on unpredictable timing conditions, such as the current block timestamp, in ways that make settlement unreliable.

For example, a marketplace might query royaltyInfo when a sale occurs but complete settlement several days later. If the applicable percentage depends on the time of the query, another query at settlement could produce a substantially different royalty amount for the same sale price.

The token contract should calculate the royalty amount from the supplied sale price and its applicable royalty policy rather than require the marketplace to infer the percentage.

Currency-independent royalty information

ERC-2981 does not prescribe the currency or token used for a sale. The interface can therefore be used for on-chain or off-chain sales in different currencies, provided the returned royalty amount is interpreted in the same unit as the input price.

Universal applicability

Although designed with NFTs in mind, the interface can be implemented by other contracts that need to communicate royalty payment information.

Implementation

An example implementation is available here.

The following OpenZeppelin implementation is from version 4.9.2.

javascript
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/common/ERC2981.sol)

pragma solidity ^0.8.0;

import "../../interfaces/IERC2981.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev 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 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._
 */
abstract contract ERC2981 is IERC2981, ERC165 {
    struct RoyaltyInfo {
        address receiver;
        uint96 royaltyFraction;
    }

    RoyaltyInfo private _defaultRoyaltyInfo;
    mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
        return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @inheritdoc IERC2981
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual override returns (address, uint256) {
        RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];

        if (royalty.receiver == address(0)) {
            royalty = _defaultRoyaltyInfo;
        }

        uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();

        return (royalty.receiver, royaltyAmount);
    }

    /**
     * @dev 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) {
        return 10000;
    }

    /**
     * @dev 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 {
        require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
        require(receiver != address(0), "ERC2981: invalid receiver");

        _defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
    }

    /**
     * @dev Removes default royalty information.
     */
    function _deleteDefaultRoyalty() internal virtual {
        delete _defaultRoyaltyInfo;
    }

    /**
     * @dev 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 {
        require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
        require(receiver != address(0), "ERC2981: Invalid parameters");

        _tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
    }

    /**
     * @dev Resets royalty information for the token id back to the global default.
     */
    function _resetTokenRoyalty(uint256 tokenId) internal virtual {
        delete _tokenRoyaltyInfo[tokenId];
    }
}

Struct

RoyaltyInfo

Stores a royalty configuration.

  • receiver: Address receiving the royalty.
  • royaltyFraction: Numerator of the royalty fraction, interpreted using the fee denominator.

State variables

_defaultRoyaltyInfo

Stores the default royalty configuration applicable to token IDs without an individual override.

_tokenRoyaltyInfo

Maps individual token IDs to token-specific royalty configurations.

Functions

supportsInterface

Reports interface support through ERC-165, including support for the ERC-2981 interface.

For background on ERC-165, see:

ERC-165: Detecting supported contract interfaces

royaltyInfo

Returns the royalty receiver and amount for a given token ID and sale price. A token-specific configuration takes precedence over the default configuration.

_feeDenominator

Returns the denominator used to calculate the royalty fraction. The displayed OpenZeppelin implementation defaults to 10,000, allowing royalties to be expressed in basis points.

_setDefaultRoyalty

Configures the default royalty recipient and fraction.

_deleteDefaultRoyalty

Removes the default royalty configuration.

_resetTokenRoyalty

Removes the token-specific royalty configuration, causing future queries to use the default configuration where applicable.

The implementation also contains _setTokenRoyalty, which sets a royalty configuration for a particular token ID. These are internal configuration methods; a derived contract must define who may invoke the corresponding administrative operations.

Test code

The example tests are available here.

Backward compatibility

ERC-2981 can be implemented alongside ERC-721 and ERC-1155 without replacing their ordinary token interfaces.

Personal observations

Can ERC-2981 actually enforce royalty payments? The answer is no: the standard defines how to obtain royalty information, not how to force a marketplace to settle it.

The implementation calculates royalties but does not incorporate that calculation into NFT transfer functions. It also does not override the historical _beforeTokenTransfer hook to require payment on every transfer.

Consider an illustrative custodial marketplace sale:

  1. The seller lists an NFT and transfers it to the marketplace under the marketplace's custody model.
  2. The buyer sends the purchase price to the marketplace.
  3. The marketplace collects its fee and distributes the remaining payment to the seller and royalty recipient.
  4. The marketplace transfers the NFT to the buyer.

Illustrative NFT marketplace settlement flow

Not all marketplaces use custody; many execute settlement through approved transfers or signed orders. The key point is the same: the settlement contract determines whether the royalty recipient is paid.

Adding mandatory royalty payments directly to token transfers raises two concerns.

  1. Existing ERC-721 or ERC-1155 integrations may no longer function as expected.
  2. Owners might have to pay a royalty even when moving NFTs between their own wallets.

Compatibility with ERC-721 and ERC-1155

Additional transfer conditions may break applications that assume ordinary token transfers are possible. An implementation can retain interface identifiers while restricting behavior, but that does not guarantee practical interoperability.

Fees for ordinary transfers

An owner may need to move an NFT between two accounts they control. If every transfer requires a royalty, even a movement without a sale would incur a payment obligation.

These trade-offs explain why ERC-2981 separates royalty information from enforcement. Projects may implement additional restrictions or settlement policies, but should carefully assess their compatibility and effects on non-sale transfers.

Citation

Zach Burks (@vexycats), James Morgan (@jamesmorgan), Blaine Malone (@blmalone), James Seibel (@seibelj), "ERC-2981: NFT Royalty Standard," Ethereum Improvement Proposals, no. 2981, September 2020. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2981.

Conclusion

ERC-2981 makes royalty information portable across compatible NFT marketplaces. It standardizes the calculation and identification of royalty payments but does not enforce those payments by itself.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

Historical recruitment notice

At the time of the original article, CryptoGames was recruiting engineers interested in blockchain, Web3, NFTs, and smart contract development.

The original notice highlighted opportunities to take ownership of work and grow as an engineer. Check the company's current recruitment information separately.