Skip to main content

RoyaltyFacet

Returns royalty information for tokens

Key Features
  • Implements ERC-2981 royaltyInfo function for external querying.
  • Accesses royalty data via diamond storage.
  • Supports token-specific and default royalty configurations.
  • Self-contained, no external dependencies beyond diamond storage access.

Overview

This facet implements ERC-2981 royalty information retrieval for tokens within a diamond. It provides an external function to query royalty details based on token ID and sale price, falling back to default royalty settings if token-specific royalties are not defined. This facet enables standard royalty distribution mechanisms for NFTs.


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("compose.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
  • Initialize default royalty information during diamond setup.
  • Ensure the RoyaltyStorage struct is correctly placed in diamond storage.
  • Verify compatibility with the ERC-2981 standard for downstream integrations.

Security Considerations

Security

Follow standard Solidity security practices. The royaltyInfo function is a view function and does not modify state. Input validation for _tokenId and _salePrice is implicitly handled by Solidity's type system. Ensure correct initialization of default royalties to prevent unintended distribution.

Was this helpful?
Last updated: