Royalty Facet
Provides ERC-2981 royalty information for tokens
- Implements ERC-2981
royaltyInfofunction for on-chain royalty queries. - Reads from shared diamond storage for default and token-specific royalty data.
- Operates as an internal facet, accessed via the diamond proxy.
- Self-contained with no external dependencies other than diamond storage access.
Overview
This facet implements the ERC-2981 royaltyInfo function, enabling a diamond to provide royalty information for tokens. It accesses shared diamond storage to retrieve default and token-specific royalty settings. Developers add this facet to integrate royalty payment logic into their NFT marketplaces or token contracts within a diamond.
Storage
RoyaltyInfo
RoyaltyStorage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc2981")) |
FEE_DENOMINATOR | uint96 | (Value: 10000) |
Functions
royaltyInfo
Returns royalty information for a given token and sale price. Returns token-specific royalty if set, otherwise falls back to default royalty. Royalty amount is calculated as a percentage of the sale price using basis points. Implements the ERC-2981 royaltyInfo function.
Parameters:
| Property | Type | Description |
|---|---|---|
_tokenId | uint256 | The NFT asset queried for royalty information. |
_salePrice | uint256 | The sale price of the NFT asset specified by _tokenId. |
Returns:
| Property | Type | Description |
|---|---|---|
receiver | address | The address designated to receive the royalty payment. |
royaltyAmount | uint256 | The royalty payment amount for _salePrice. |
Best Practices
- Integrate this facet into your diamond to enable ERC-2981 compliant royalty queries.
- Ensure the
RoyaltyStoragestruct is correctly initialized with default royalty information during diamond deployment. - Use the
royaltyInfofunction through the diamond proxy to retrieve royalty details for token sales.
Security Considerations
The royaltyInfo function is a view function and does not pose reentrancy risks. Input validation for _tokenId and _salePrice is handled by the function logic to calculate royalty amounts. Access control is implicit as the function is external and called through the diamond proxy, which routes calls to the appropriate facet. Follow standard Solidity security practices for handling token IDs and sale prices.