EIP-2981: Implementing NFT Royalties On-Chain

GoldRush TeamUpdated 12 min read

How EIP-2981 NFT royalties work: royaltyInfo, basis points, OpenZeppelin 5 contract code, reading a collection's royalty, and why marketplaces can skip it.

EIP-2981 (also called ERC-2981) is the Ethereum standard for NFT royalties. It adds one function to an NFT contract, royaltyInfo(tokenId, salePrice), which returns the address that should receive a royalty and how much it should get for a sale at that price. Marketplaces call it when an NFT sells and, if they choose to honour it, send that amount to the receiver. The standard doesn't move any money itself: a royalty set with EIP-2981 is a published request, not an on-chain guarantee.

This guide covers what the standard specifies, how to implement it with OpenZeppelin 5 for ERC-721 and ERC-1155, how a marketplace reads and pays it, how to look up the royalty any collection asks for, and where enforcement stands today.

What EIP-2981 specifies

ERC-2981 has status Final. Before it, each marketplace kept its own royalty settings, so a creator had to configure fees on every platform and a royalty set on one didn't follow the NFT to another. EIP-2981 puts the royalty in the NFT contract, where any marketplace can read it. It works with ERC-721 and ERC-1155 tokens.

The whole interface is one function plus ERC-165 interface detection:

interface IERC2981 is IERC165 {    /// ERC-165 identifier: bytes4(keccak256("royaltyInfo(uint256,uint256)")) == 0x2a55205a    function royaltyInfo(uint256 tokenId, uint256 salePrice)        external        view        returns (address receiver, uint256 royaltyAmount);}

The rules that matter in practice:

  • The royalty is a percentage of the sale price. The contract must compute royaltyAmount from salePrice, never return a fixed amount, and apply the same percentage whatever the price. It may round up or down.
  • It has no currency. royaltyInfo doesn't know whether the sale was in ETH, WETH or USDC. The marketplace must pay the royalty in the same unit as the sale price it passed in.
  • It is per token. tokenId is an argument, so each token can have its own rate and receiver.
  • Payment is voluntary. The standard says so: a transferFrom can't tell a sale from a wallet moving its own NFTs, so royalties can't be charged on transfers. A marketplace that doesn't implement EIP-2981 pays nothing.
  • Detection uses supportsInterface(0x2a55205a). A contract that implements the standard must return true for that ID.
  • Marketplaces shouldn't send zero-value payments. If royaltyAmount is 0, skip the transfer.

Royalty rates in basis points

Royalties are almost always set in basis points: 1 basis point is 0.01%, so 10,000 is 100%. OpenZeppelin's implementation stores a fee numerator and divides by _feeDenominator(), which is 10,000 by default:

royaltyAmount = salePrice × feeNumerator / 10,000   (rounded down)
feeNumerator Royalty On a 1 ETH sale On a 2,500 USDC sale
100 1% 0.01 ETH 25 USDC
250 2.5% 0.025 ETH 62.5 USDC
500 5% 0.05 ETH 125 USDC
1,000 10% 0.1 ETH 250 USDC

Amounts are in the token's smallest unit (wei for ETH, 10-6 for USDC), which is why rounding rarely matters: at 5%, a sale of 999 wei pays 49 wei. The numerator is a uint96, and OpenZeppelin reverts if it's larger than the denominator.

Implement EIP-2981 on an ERC-721 with OpenZeppelin 5

OpenZeppelin Contracts ships EIP-2981 as ERC2981, and ERC721Royalty combines it with ERC-721 and already merges the two supportsInterface implementations. This contract sets a 5% collection-wide royalty at deployment and lets the owner change it, or give single tokens their own rate:

// SPDX-License-Identifier: MITpragma solidity ^0.8.24; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";import {ERC721Royalty} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol";import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; contract RoyaltyNFT is ERC721Royalty, Ownable {    uint256 public constant MAX_SUPPLY = 100;    uint256 private _nextTokenId;    string private _baseTokenURI;     error SoldOut();     constructor(address royaltyReceiver, string memory baseTokenURI)        ERC721("Royalty NFT", "RNFT")        Ownable(msg.sender)    {        _baseTokenURI = baseTokenURI;        // 500 basis points = 5% of every sale price, paid to royaltyReceiver.        _setDefaultRoyalty(royaltyReceiver, 500);    }     function mint(address to) external onlyOwner returns (uint256 tokenId) {        tokenId = _nextTokenId++;        if (tokenId >= MAX_SUPPLY) revert SoldOut();        _safeMint(to, tokenId);    }     // Change the collection-wide royalty. feeBps is in basis points: 250 = 2.5%.    function setDefaultRoyalty(address receiver, uint96 feeBps) external onlyOwner {        _setDefaultRoyalty(receiver, feeBps);    }     // Give one token its own receiver and rate, overriding the default.    function setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeBps) external onlyOwner {        _setTokenRoyalty(tokenId, receiver, feeBps);    }     // Send one token back to the default royalty.    function resetTokenRoyalty(uint256 tokenId) external onlyOwner {        _resetTokenRoyalty(tokenId);    }     function _baseURI() internal view override returns (string memory) {        return _baseTokenURI;    }}

What each part does:

  • _setDefaultRoyalty(receiver, feeNumerator) sets the royalty for every token that has no royalty of its own. It reverts with ERC2981InvalidDefaultRoyalty if the rate is above 100% and ERC2981InvalidDefaultRoyaltyReceiver for the zero address.
  • _setTokenRoyalty(tokenId, receiver, feeNumerator) overrides the default for one token, for example a 1-of-1 with a collaborator as receiver. _resetTokenRoyalty removes the override, and _deleteDefaultRoyalty removes the default.
  • royaltyInfo is inherited. It looks up the token's own royalty, falls back to the default, and returns salePrice * fee / 10000. It doesn't check that the token exists, so an unminted ID returns the default royalty.
  • supportsInterface is inherited from ERC721Royalty and answers true for ERC-165, ERC-721, ERC-721 metadata and 0x2a55205a.
  • The setters are onlyOwner. Royalty settings are mutable unless you leave out the setters or renounce ownership. Buyers can read them, so changing a rate after a sale is visible to anyone who checks.

Compared with OpenZeppelin 4-era tutorials: Counters.sol is gone in version 5 (use a plain uint256 counter, as above), Ownable takes the initial owner in its constructor, and errors are custom errors rather than revert strings. OpenZeppelin 5 needs Solidity 0.8.20 or later.

The receiver gets the whole royalty. To split it between collaborators, make the receiver a payment-splitter contract that divides what it receives; EIP-2981 itself only returns one address.

Add royalties to an ERC-1155

OpenZeppelin has no ERC1155Royalty, so inherit ERC1155 and ERC2981 directly and say which supportsInterface to use, since both parents define it:

// SPDX-License-Identifier: MITpragma solidity ^0.8.24; import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";import {ERC2981} from "@openzeppelin/contracts/token/common/ERC2981.sol";import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; contract Editions is ERC1155, ERC2981, Ownable {    constructor(address royaltyReceiver, string memory uri_) ERC1155(uri_) Ownable(msg.sender) {        _setDefaultRoyalty(royaltyReceiver, 750); // 7.5%    }     function mint(address to, uint256 id, uint256 amount) external onlyOwner {        _mint(to, id, amount, "");    }     // Both parents implement ERC-165, so say which one answers.    function supportsInterface(bytes4 interfaceId) public view override(ERC1155, ERC2981) returns (bool) {        return super.supportsInterface(interfaceId);    }}

royaltyInfo(7, 2 ether) on this contract returns the receiver and 0.15 ether. The tokenId is the ERC-1155 token ID, and salePrice is the total paid for however many copies were sold.

How a marketplace pays the royalty

On the marketplace side, settling a sale means checking for the interface, asking for the royalty at the agreed price, and paying it out of the proceeds. This library does the split; ERC165Checker returns false instead of reverting when the NFT contract doesn't implement ERC-165 at all:

// SPDX-License-Identifier: MITpragma solidity ^0.8.24; import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";import {IERC2981} from "@openzeppelin/contracts/interfaces/IERC2981.sol"; library RoyaltySplit {    // How a marketplace splits a sale price between the royalty receiver and the seller.    function split(address collection, uint256 tokenId, uint256 price)        internal        view        returns (address receiver, uint256 royalty, uint256 toSeller)    {        // ERC165Checker returns false, instead of reverting, for contracts without ERC-165.        if (ERC165Checker.supportsInterface(collection, type(IERC2981).interfaceId)) {            (receiver, royalty) = IERC2981(collection).royaltyInfo(tokenId, price);            if (royalty > price) royalty = 0; // never trust a contract to stay below the price        }        toSeller = price - royalty;    }}

The marketplace then transfers royalty to receiver (skipping it when it's 0) and toSeller to the seller, in the same token the buyer paid with. Many marketplaces also cap the royalty they'll honour, since royaltyInfo can return anything up to the full price.

Read a collection's royalty

Anyone can read what a collection asks for, with one eth_call to supportsInterface and one to royaltyInfo. This uses viem and a public Ethereum RPC endpoint.

You need Node.js 22 (the version this was run on), and the packages pinned below; the Solidity above compiles against the same OpenZeppelin release. The script uses top-level await, so save it as an ES module, royalties.mjs, and run node royalties.mjs:

npm install viem@2.58.4 @openzeppelin/contracts@5.6.1
import { createPublicClient, http, parseAbi, parseEther, formatEther } from "viem";import { mainnet } from "viem/chains"; const client = createPublicClient({    chain: mainnet,    transport: http("https://ethereum-rpc.publicnode.com"),}); const abi = parseAbi([    "function supportsInterface(bytes4 interfaceId) view returns (bool)",    "function royaltyInfo(uint256 tokenId, uint256 salePrice) view returns (address receiver, uint256 royaltyAmount)",]);const ERC2981_INTERFACE_ID = "0x2a55205a"; // The royalty a collection asks for on one sale, or null if it doesn't implement EIP-2981.async function getRoyalty(collection, tokenId, salePrice) {    const supported = await client        .readContract({ address: collection, abi, functionName: "supportsInterface", args: [ERC2981_INTERFACE_ID] })        .catch(() => false); // no ERC-165 at all    if (!supported) return null;    const [receiver, royaltyAmount] = await client.readContract({        address: collection,        abi,        functionName: "royaltyInfo",        args: [tokenId, salePrice],    });    return { receiver, royaltyAmount, bps: Number((royaltyAmount * 10_000n) / salePrice) };} const MOONBIRDS = "0x23581767a106ae21c074b2276D25e5C3e136a68b";const royalty = await getRoyalty(MOONBIRDS, 1n, parseEther("1"));console.log(royalty.receiver, formatEther(royalty.royaltyAmount), "ETH", royalty.bps, "bps");// 0x73061676D7D2790f097E2d618F319275D3D3328E 0.01 ETH 100 bps const BAYC = "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D";console.log(await getRoyalty(BAYC, 1n, parseEther("1")));// null

The printed values are from a run on 21 November 2026. Moonbirds asks for 1% through EIP-2981. The Bored Ape Yacht Club contract predates the standard and returns false for 0x2a55205a, so any royalty on it is set off-chain, marketplace by marketplace. Plenty of large collections are in the same position, so check before you assume a contract has a royalty.

Check every collection a wallet holds

To audit the royalties on a wallet's NFTs, list its collections with an NFT API and call getRoyalty for each one. NFTs for an address returns every ERC-721 and ERC-1155 collection the wallet holds on one chain, with its token IDs. no-nft-asset-metadata=true leaves out images and metadata, which this doesn't need. Add this to the same royalties.mjs file, below getRoyalty (it uses getRoyalty and parseEther from it), and set your key in GOLDRUSH_API_KEY:

const API = "https://api.covalenthq.com/v1"; // Royalty settings for every collection a wallet holds on Ethereum.async function royaltiesForWallet(wallet) {    const url = `${API}/eth-mainnet/address/${wallet}/balances_nft/?no-spam=true&no-nft-asset-metadata=true`;    const res = await fetch(url, {        headers: { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}` },    });    if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);    const { data } = await res.json();     const salePrice = parseEther("1");    const rows = [];    for (const collection of data.items) {        const tokenId = collection.nft_data?.[0]?.token_id;        if (tokenId === undefined) continue;        const royalty = await getRoyalty(collection.contract_address, BigInt(tokenId), salePrice);        rows.push({            collection: collection.contract_name,            royalty: royalty ? `${royalty.bps / 100}%` : "no EIP-2981",            receiver: royalty?.receiver ?? "",        });    }    return rows;} console.table(await royaltiesForWallet("vitalik.eth"));

For a wallet holding Moonbirds and a Bored Ape, the table reads Moonbirds 1% 0x7306…328E and BoredApeYachtClub no EIP-2981. The check uses one token per collection, which is enough for a collection-wide default; if a collection sets per-token royalties, call getRoyalty for each token in nft_data. NFTs for an address is billed in credits: 1 per call, whatever the wallet holds. It works on 12 chains; change eth-mainnet and the RPC endpoint together to check another one.

Handle errors from the GoldRush API

royaltiesForWallet throws on any non-2xx status with the body in the message. A failed call returns the same envelope as a successful one, with data set to null, error set to true and the reason in error_message; error_code is a JSON number equal to the HTTP status. The docs show this body for a chain name the API doesn't recognize:

{ "data": null, "error": true, "error_message": "Chain nosuchchain-mainnet not supported.", "error_code": 501 }

A 501 means the request was well formed but the chain or endpoint can't serve it, so retrying it unchanged won't help; check the chain name before you swap eth-mainnet for another. A 401 means the key is missing or wrong, and with no Authorization header at all the edge proxy returns an HTML 401 page rather than JSON, which res.text() still reads. Failed requests cost no credits. Every code is listed in the error handling docs.

Are EIP-2981 royalties enforced?

No. EIP-2981 tells a marketplace what to pay; nothing in the standard makes it pay. An NFT can also change hands through a plain transfer, with the payment made somewhere else, and the contract can't tell that apart from a gift.

Marketplaces have taken different positions on this, and changed them:

  • Marketplace-enforced fees. For years most large marketplaces paid the creator's royalty on every sale. Competition on fees changed that in 2022, when several marketplaces made royalties optional or capped them.
  • Operator filtering. In 2022 OpenSea published the Operator Filter Registry: collections could block their tokens from being approved for or transferred by marketplaces that didn't pay creator fees. It depended on the whole ecosystem opting in, which didn't happen. In August 2023 OpenSea announced that it would stop blocking marketplaces through the filter on 31 August 2023, make creator fees optional for new collections from that date, and keep enforcing fees for collections that had used the filter until 29 February 2024. The registry's repository is now marked deprecated.
  • Transfer-restricted tokens. Some standards, such as Limit Break's Creator Token Standards (ERC-721C), go further: the contract only lets approved operators move tokens, so trades can only go through marketplaces that pay. The cost is that the token is less freely transferable, and wallets, lending protocols or other contracts that aren't on the list can't move it.

In practice, set an EIP-2981 royalty so that every marketplace that honours royalties can find it, and treat the income as something marketplaces and buyers may or may not pay. If royalties have to be guaranteed, the only on-chain options restrict how the token can move, and that trade-off belongs in your design, not in a footnote.

Frequently asked questions

What is EIP-2981?

EIP-2981, also called ERC-2981, is the Ethereum NFT royalty standard. It adds a royaltyInfo(tokenId, salePrice) function to ERC-721 and ERC-1155 contracts that returns the royalty receiver and the amount owed for a sale at that price, so any marketplace can look up the royalty the creator wants.

Are EIP-2981 royalties enforced on-chain?

No. The standard only signals a royalty, and says payment is voluntary: the contract can't tell a sale from a wallet moving its own NFT, so it can't charge on transfer. Marketplaces decide whether to pay. Enforcing royalties on-chain means restricting which operators can transfer the token.

What is the EIP-2981 interface ID?

0x2a55205a, the selector of royaltyInfo(uint256,uint256). A contract that implements EIP-2981 returns true from supportsInterface(0x2a55205a), which is how marketplaces detect it. In Solidity, type(IERC2981).interfaceId gives the same value.

How do I calculate an NFT royalty in basis points?

Multiply the sale price by the rate in basis points and divide by 10,000. 500 basis points is 5%, so a 2 ETH sale owes 0.1 ETH. OpenZeppelin's ERC2981 uses 10,000 as its default fee denominator and rounds down.

Can each NFT have a different royalty?

Yes. royaltyInfo takes the token ID, so the contract can return a different receiver and rate per token. With OpenZeppelin, _setTokenRoyalty overrides the collection default for one token and _resetTokenRoyalty removes the override.

Can I change the royalty after deployment?

Only if the contract has a function that calls _setDefaultRoyalty or _setTokenRoyalty, like the owner-only setters in this guide. Without such a function the royalty is fixed at deployment. Anyone can read the current setting with royaltyInfo.

Does EIP-2981 work with ERC-1155?

Yes. Inherit OpenZeppelin's ERC1155 and ERC2981 and override supportsInterface to combine them. The royalty is calculated on the total sale price, however many copies of the token ID were sold.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.