ERC2981 - Let royaltyFraction (royalty fee) accessible for each tokens
See original GitHub issueđ§ Motivation I want to display the royalty percentage/fee (royaltyFraction) on NFTs that are listed on my marketplace app. I want my users to be acknowledged for the price cuts.
đ Details
The royalty fraction information is already recorded in a struct for each tokensâ with royalty set inside the ERC2981.sol. I want to access that information and show it on my marketplace app. Currently, I have modified the royaltyInfo function to return the royaltyFraction
like this:
/**
* @inheritdoc IERC2981
*/
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256, uint96) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount, royalty.royaltyFraction);
}
I have also modified the related function inside the IERC2981 to return the royaltyInfo as follows:
interface IERC2981 is IERC165 {
/**
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount, uint96 royaltyFraction);
}
There could be a better way to achieve this. Please let us access royaltyFraction
so users of my marketplace can also see the royalty fee (royaltyFraction) information.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
EIP-2981: NFT Royalty Standard
A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal support for royalty payments ...
Read more >ERC2981: NFT Royalty Standard. What is it, and How do You ...
It can be used to set a global royalty for each token, or a specific royalty for each different token. The royalty to...
Read more >CrofamLadiesRETRO (RETROLADIES) Token Tracker
Royalty information can be specified globally for all token ids via {_setDefaultRoyalty} ... "ERC2981: royalty fee will exceed salePrice"); require(receiver ...
Read more >Adding Royalty to NFT Smart Contract for Opensea ... - YouTube
ERC2981 is a standardized way to retrieve royalty payment information for ... and add ERC2981 to your NFT Smart Contract so it can...
Read more >NFT - Etherscan
Sponsored Binance - Buy over 350 tokens in seconds with fees as low as 0% 0% FEES ... contract NFT is ERC721Enumerable, Ownable,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am going to assume you are building a website marketplace. Something similar to OpenSea. You did not say it clearly, but I guess the most logical âmarketplaceâ case.
Calling the royaltyInfo for each NFT might indeed be a pain, but that is the design of the ERC that each NFT can have a different fee. The good thing here is that if a backend server or a website front does this call, the call is free (as far as gas is concerned). You donât pay gas when you want to check the state of the blockchain.
Now you can use the existing
royaltyInfo()
function with a dummy price ⌠or you could call another non standard function ⌠in both cases the cost will be the same.The difference in gas cost is for whoever is going to deploy the contract. The more features there are, the most expensive it is, so you definitely donât want to deploy features that you donât need.
I was probably not clear to what Iâm meaning by interoperability here. Its true that adding an additional function will not remove anything from the contract. Contracts would remain ERC2981 compliant, so that is not the issue.
My concern is with your marketplace relying on a specific function being present. By doing so, you are not making your marketplace ERC2981 compliant, and you will incorrectly interact with contracts that are âonlyâ ERC2981. IMO it would be better if your marketplace doesnât make any assumptions about the contract interface beyond what is standardized in ERCs.
royaltyInfo
for each NFT listed on my marketplace with a dummy sale price will also run some calculations (like royalty amount) that I donât need and thus I believe this would cause unnecessary gas consumption. This is mainly what I am trying to get away from.ERC2981.sol
follows the âThe key words âMUSTâ, âMUST NOTâ, âREQUIREDâ, âSHALLâ, âSHALL NOTâ, âSHOULDâ, âSHOULD NOTâ, âRECOMMENDEDâ, âMAYâ, and âOPTIONALâ in this document are to be interpreted as described in RFC 2119.â And I (as a junior) believe adding a getter for the percentage would break any of these.With the addition of a simple getter, marketplaces would be able to display the royalty percentage (for sellers and buyers) without additional gas consumption of royalty amount calculation and it would be much more clean from the perspective of developers.
Sorry If am missing something with my logic.