02.EIP-2981
2023-10-18 17:54:00 # 26.EIP

EIP-2981

简述

  • 起因:某个艺术家前期不出名,以很低价出售了作品A,成名之后,作品A无法为他带来收益。也就是说,艺术家一次性的销售之后,就无法获得额外收入,无法享受二级市场中产生的每一次转售收入的特定比例收入分成。
  • EIP-2981解决跨平台版税支付不兼容的问题:各个二级市场平台实际出售和转售NFT是在自己的合约中实现的,因此二级市场平台有着自己独有一套的方案。EIP-2981想让大家达成标准,搞了一个通用模板,各个二级市场平台通过查询royaltyInfo来实施某种将版税转移给版税接收者的方法(当然是靠自觉啦,二级市场平台不遵循也没办法)
  • 简单来说:NFT的拥有者RoyaltyInfo.receiver相当于艺术家,在本次这个NFT转售的时候,都会转发royaltyFraction比例的金额到拥有者的地址中
  • 版税如果以ETH为单位,则支付版税也要用ETH;如果是ERC20支付同理
  • 由于RoyaltyInfo.receiver可能在自己的多个钱包中来回折腾这个NFT,这没有进行交易,因此这个版税在这种情况下不会被收取,这个功能需要实现

例子

我们使用OZ的实现

  • ERC721Royalty实现了ERC2981和ERC721

版税信息

1
2
3
4
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction; // 版权税
}

代码:只是实现了EIP-2981,实际转账扣除的版税尚未实现,实际的二级市场平台需要自己实现,版税的金额记录在RoyaltyInfo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract MyToken is ERC721, ERC721Royalty, ERC721URIStorage, Ownable {

error OwnerError(string errorMsg,address owner,uint256 tokenId);

using Counters for Counters.Counter;

Counters.Counter private _tokenIdCounter;

constructor() ERC721("MyToken", "MTK") {}

function _baseURI() internal pure override returns (string memory) {
return "https://thinkingchain.app/";
}

function safeMint(address to, string memory uri) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}

// The following functions are overrides required by Solidity.

function _burn(uint256 tokenId) internal override(ERC721,ERC721Royalty, ERC721URIStorage) {
super._burn(tokenId);
}

function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}

// 设置默认的版权税
function setDefaultRoyalty(address receiver, uint96 feeNumerator) public onlyOwner {
_setDefaultRoyalty(receiver,feeNumerator);
}

// 个人设置NFT版权税
function setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) public {
address owner = ownerOf(tokenId);
if(owner != msg.sender){
revert OwnerError("Not owner",owner,tokenId);
}
_setTokenRoyalty(tokenId,receiver,feeNumerator);
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Royalty) returns (bool) {
return super.supportsInterface(interfaceId);
}

}
Prev
2023-10-18 17:54:00 # 26.EIP
Next