---
eip: 2981
label: ERC-2981
title: NFT Royalty Standard
status: Final
type: Standards Track
category: ERC
created: 2020-09-15
requires: 165
official: https://eips.ethereum.org/EIPS/eip-2981
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2981.md
canonical: https://eips.huatuo.xyz/zh/eip-2981/
lang: zh
tldr: 一个只有一个函数的接口 `royaltyInfo(tokenId, salePrice)`，让任何 NFT 都能以所有市场都能读取的方式告诉市场：谁应该收到版税，以及收多少。
tags: [nft, royalty, erc721, erc1155, marketplace]
---

# ERC-2981: NFT Royalty Standard

> A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal support for royalty payments across all NFT marketplaces and ecosystem participants.

**TL;DR:** 一个只有一个函数的接口 `royaltyInfo(tokenId, salePrice)`，让任何 NFT 都能以所有市场都能读取的方式告诉市场：谁应该收到版税，以及收多少。

## 它解决什么问题？

在 ERC-2981 之前，每个 NFT 市场都以自己的私有格式存储创作者版税。在一个市场设置了 10 % 版税的艺术家，当 NFT 在另一个市场转售时一分钱也拿不到，因为第二个市场无从得知这些条款。

ERC-2981 把版税信息放在 NFT 合约本身，通过一个标准函数对外提供，因此任何市场（无论链上还是链下）都能查询并支付。

## 它如何运作

NFT 合约实现一个 view 函数，并通过 [ERC-165](/eip-165/) 以接口 ID `0x2a55205a` 声明它：

```solidity
function royaltyInfo(uint256 tokenId, uint256 salePrice)
    external view returns (address receiver, uint256 royaltyAmount);
```

- 市场传入成交价；合约返回收款方和应付的**金额**。
- 金额必须是 **`salePrice` 的一个百分比**，并且合约不得假设货币种类：不能是固定金额，也不能与常量比较。市场以与成交相同的单位支付版税（ETH 成交就付 ETH 版税，USDC 成交就付 USDC 版税）。
- 百分比可以因代币而异，或随可预测的状态变化（例如随转手次数递减），但不应依赖 `block.timestamp` 这类不可预测的值。
- 向上或向下取整都可以。
- 当金额为 `0` 时，市场不应发送零金额的付款。

它适用于 [ERC-721](/eip-721/) 和 [ERC-1155](/eip-1155/)，但任何能通过 ID 标识资产的合约都可以实现它。

## 示例代码

一个最小的 ERC-721，整个合集使用单一的版税（以基点计）：

```solidity
// 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);
    }
}
```

市场端（ethers v6）：

```ts
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);
}
```

## 需要注意

- 版税是**自愿的**。该标准只报告应付的金额，无法强制支付，因为普通的 `transferFrom` 分不清一次出售和钱包之间的转移。市场是否支付取决于它自己的政策。
- 在多个收款方之间分账不在范围之内：请把 `receiver` 指向一个分账合约。
- OpenZeppelin 提供了 `ERC2981` 扩展，支持默认版税和按代币设置的版税；请优先使用它，而不是自己手写代码。
- 状态为 **Final**。[ERC-4910](/eip-4910/) 是另一项更复杂的提案，试图强制执行版税。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2981
