Skip to main content

Royalty Facet

Provides ERC-2981 royalty information for tokens

Key Features
  • Implements ERC-2981 royaltyInfo function 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

Definition
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}

RoyaltyStorage

Definition
struct RoyaltyStorage {
RoyaltyInfo defaultRoyaltyInfo;
mapping(uint256 tokenId => RoyaltyInfo) tokenRoyaltyInfo;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc2981"))
FEE_DENOMINATORuint96(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.

function royaltyInfo(uint256 _tokenId, uint256 _salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);

Parameters:

PropertyTypeDescription
_tokenIduint256The NFT asset queried for royalty information.
_salePriceuint256The sale price of the NFT asset specified by _tokenId.

Returns:

PropertyTypeDescription
receiveraddressThe address designated to receive the royalty payment.
royaltyAmountuint256The royalty payment amount for _salePrice.

Best Practices

Best Practice
  • Integrate this facet into your diamond to enable ERC-2981 compliant royalty queries.
  • Ensure the RoyaltyStorage struct is correctly initialized with default royalty information during diamond deployment.
  • Use the royaltyInfo function through the diamond proxy to retrieve royalty details for token sales.

Security Considerations

Security

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.