EIPs Explained

ERC-2981 · Final · ERC · 2020-09-15

ERC-2981: NFT Royalty Standard

A one-function interface, `royaltyInfo(tokenId, salePrice)`, that lets any NFT tell marketplaces who should receive a royalty and how much, in a way every marketplace can read.

What problem does it solve?

Before ERC-2981, each NFT marketplace stored creator royalties in its own private format. An artist who set a 10 % royalty on one marketplace got nothing when the NFT was resold on another, because the second marketplace had no way to learn the terms.

ERC-2981 puts royalty information on the NFT contract itself behind a standard function, so any marketplace — on-chain or off — can look it up and pay it.

How it works

The NFT contract implements one view function and advertises it through ERC-165 with interface ID 0x2a55205a:

function royaltyInfo(uint256 tokenId, uint256 salePrice)
    external view returns (address receiver, uint256 royaltyAmount);
  • The marketplace passes the sale price; the contract returns the recipient and the amount owed.
  • The amount must be a percentage of salePrice, and the contract must not assume a currency: no fixed amounts and no comparisons against constants. The marketplace pays the royalty in the same unit as the sale (ETH sale → ETH royalty, USDC sale → USDC royalty).
  • The percentage may vary by token or by predictable state (for example, decreasing with the number of transfers), but should not depend on unpredictable values like block.timestamp.
  • Rounding up or down is fine.
  • Marketplaces should not send a zero-value payment when the amount is 0.

It works with ERC-721 and ERC-1155, but any contract that can identify assets by ID may implement it.

Sample code

A minimal ERC-721 with a single collection-wide royalty in basis points:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract RoyaltyNFT is ERC721 {
    address public immutable royaltyReceiver;
    uint96 public constant ROYALTY_BPS = 500; // 5 %

    constructor(address receiver) ERC721("Art", "ART") {
        royaltyReceiver = receiver;
        _mint(msg.sender, 1);
    }

    function royaltyInfo(uint256, uint256 salePrice)
        external view returns (address, uint256)
    {
        return (royaltyReceiver, (salePrice * ROYALTY_BPS) / 10_000);
    }

    function supportsInterface(bytes4 id) public view override returns (bool) {
        return id == 0x2a55205a || super.supportsInterface(id);
    }
}

Marketplace side (ethers v6):

const nft = new Contract(addr, [
  "function supportsInterface(bytes4) view returns (bool)",
  "function royaltyInfo(uint256,uint256) view returns (address,uint256)",
], provider);
if (await nft.supportsInterface("0x2a55205a")) {
  const [receiver, amount] = await nft.royaltyInfo(tokenId, salePrice);
}

Things to know

  • Royalties are voluntary. The standard only reports what is owed; it cannot force payment, because an ordinary transferFrom cannot tell a sale from a move between wallets. Whether a marketplace pays is its own policy.
  • Splitting among several recipients is out of scope: point receiver at a splitter contract.
  • OpenZeppelin ships an ERC2981 extension with default and per-token royalties; prefer it over hand-rolled code.
  • Status is Final. ERC-4910 is a separate, more complex proposal that tries to enforce royalties.

#nft #royalty #erc721 #erc1155 #marketplace

Details

Authors
Zach Burks (@vexycats), James Morgan (@jamesmorgan), Blaine Malone (@blmalone), James Seibel (@seibelj)
Status
Final
Type
Standards Track / ERC
Created
2020-09-15
Requires
Required by

Machine-readable: Markdown · JSON