The RoyaltyInfo Interface is a technical specification defined by the Ethereum Request for Comment 2981 (ERC-2981) standard. It provides a single, universal function, royaltyInfo(uint256 _tokenId, uint256 _salePrice), that returns the recipient address and royalty amount for a given token and sale price. This allows any marketplace or decentralized application (dApp) to query an NFT contract directly to discover and enforce creator royalties in a consistent manner, moving away from fragmented, off-chain metadata or platform-specific implementations.
RoyaltyInfo Interface
What is the RoyaltyInfo Interface?
A standardized smart contract interface for on-chain royalty information, enabling NFTs to programmatically declare how secondary sales revenue should be distributed.
Prior to ERC-2981, there was no reliable, on-chain method for smart contracts to declare royalty information. Creators relied on marketplaces voluntarily honoring off-chain data or implementing proprietary, non-interoperable solutions. The RoyaltyInfo Interface solves this by embedding the royalty logic directly into the NFT's smart contract. When a secondary sale occurs on a compliant marketplace, the platform can call the royaltyInfo function, receive the payment details, and automatically route the specified percentage to the creator's wallet as part of the transaction.
Implementing the interface involves overriding the royaltyInfo function within an NFT contract, such as one based on ERC-721 or ERC-1155. The function's logic determines how royalties are calculated—typically a percentage of the _salePrice—and who receives them. This can be a fixed address, a payment splitter contract for multiple recipients, or even dynamic logic based on the _tokenId. The returned royalty amount must be denominated in the same base unit as the sale price (e.g., wei for ETH).
For developers and marketplace builders, supporting the RoyaltyInfo Interface is crucial for interoperability. Major marketplaces like OpenSea and LooksRare recognize ERC-2981, allowing creators to be compensated automatically across platforms. It represents a significant shift toward programmable creator economies, ensuring that royalty enforcement is not a policy choice of a centralized platform but a verifiable property of the digital asset itself, executable by any compliant smart contract.
How the RoyaltyInfo Interface Works
The RoyaltyInfo interface is a standardized smart contract function that enables on-chain, programmatic enforcement of creator royalties for Non-Fungible Tokens (NFTs).
Defined by the ERC-2981 standard, the RoyaltyInfo interface provides a single, mandatory function: royaltyInfo(uint256 tokenId, uint256 salePrice). This function returns two critical pieces of information: the recipient address where royalty payments should be sent and the royalty amount to be paid, calculated from the provided salePrice. By standardizing this lookup, any marketplace, aggregator, or smart contract can query an NFT contract to discover and respect its royalty policy, moving away from fragile off-chain metadata or platform-specific configurations.
The core mechanism involves a simple calculation performed inside the royaltyInfo function. When a secondary sale occurs, the marketplace calls this function, passing the specific tokenId and the final salePrice. The contract's internal logic then determines the payout, typically by applying a fixed percentage (e.g., 5%) or a custom rule defined per token or collection. The returned royaltyAmount is usually calculated as (salePrice * royaltyFraction) / 10000, where the fraction is expressed in basis points (e.g., 500 for 5%). This amount is then transferred directly to the receiver address as part of the sale transaction.
Implementing the interface correctly is crucial for interoperability. A well-formed RoyaltyInfo function must handle two key scenarios: returning valid data for tokens that support royalties and reverting or returning zero values for tokens that do not. Developers often extend this by adding administrative functions—like setRoyaltyInfo—to allow the royalty recipient or rate to be updated, though these are not part of the core interface. This design ensures backward compatibility, as wallets and marketplaces that do not support ERC-2981 can simply ignore the function without breaking the NFT.
The widespread adoption of RoyaltyInfo has significantly impacted the NFT ecosystem. It provides a trust-minimized and composable method for enforcing creator economics, reducing reliance on individual marketplace policies. Major platforms like OpenSea and LooksRare have integrated support, automatically routing payments based on the on-chain data. However, its effectiveness ultimately depends on marketplace compliance, as the standard is a specification for information, not a mechanism that can force payment on non-compliant platforms or peer-to-peer transfers.
Key Features of the RoyaltyInfo Interface
The RoyaltyInfo interface is a standardized smart contract interface defined in ERC-2981 that enables NFTs to declare on-chain royalty payment information for secondary market sales.
Standardized Royalty Declaration
The interface provides a single, universal function, royaltyInfo(uint256 tokenId, uint256 salePrice), that returns the recipient address and royalty amount for a given token and sale price. This eliminates the need for marketplaces to implement custom, per-collection royalty logic, creating a predictable and interoperable standard.
On-Chain Enforcement Foundation
By encoding royalty logic directly into the NFT's smart contract, the RoyaltyInfo interface provides the foundational data layer for on-chain enforcement. While the interface itself does not enforce payments, decentralized marketplaces and protocols can query it programmatically to calculate and route royalties automatically, making them a verifiable part of the transaction flow.
Flexible Royalty Models
The interface supports various royalty strategies through its implementation logic:
- Fixed Percentage: A set percentage (e.g., 5%) of the sale price.
- Tiered or Custom Logic: Royalties can be programmed to change based on token ID, sale price thresholds, or other on-chain conditions.
- Dynamic Recipients: Funds can be sent to a single wallet, a multisig, or a smart contract for further distribution.
Backwards Compatibility
ERC-2981 is designed to be backwards compatible with existing NFT standards like ERC-721 and ERC-1155. Collections can adopt the RoyaltyInfo interface through a straightforward upgrade to their smart contract, adding royalty functionality without breaking existing integrations or requiring a token migration.
Marketplace Integration
Major NFT marketplaces (e.g., OpenSea, Blur, LooksRare) and aggregators query the royaltyInfo function to determine fee obligations before a sale is executed. This integration is critical for creating a consistent royalty experience for creators across different trading platforms, reducing fragmentation.
Limitations and Considerations
The interface has inherent limitations that shape its use:
- Optional Enforcement: Adherence is voluntary for marketplaces; it does not force payment on non-compliant platforms or peer-to-peer (P2P) transfers.
- Gas Costs: Querying and calculating royalties on-chain adds marginal gas overhead to transactions.
- Implementation Responsibility: The accuracy and logic of payouts depend entirely on the correctness of the smart contract's
royaltyInfoimplementation.
Code Example: The Interface & a Basic Implementation
This section demonstrates how the `RoyaltyInfo` interface is defined and implemented in a smart contract, providing a concrete example of how royalty logic is structured on-chain.
The core of any royalty implementation is the RoyaltyInfo interface, a standardized function signature that marketplaces and other contracts call to retrieve payment details. Its canonical form, as defined by standards like EIP-2981, is function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address receiver, uint256 royaltyAmount). This function takes the token's ID and its sale price as inputs and returns the address to receive the royalty and the calculated royalty amount. This simple, predictable interface is what allows decentralized exchanges and NFT marketplaces to automatically discover and pay royalties without prior configuration.
A basic implementation of this interface involves storing the royalty recipient and basis points (where 100 basis points equals 1%) within the contract. For example, a contract might store address private _royaltyRecipient and uint96 private _royaltyBasisPoints. The royaltyInfo function would then calculate the amount by performing the operation (salePrice * _royaltyBasisPoints) / 10000 and return this value alongside the recipient's address. This fixed-percentage model is common, but the interface allows for more complex logic, such as tiered royalties or dynamic recipient addresses based on the tokenId.
Implementing RoyaltyInfo correctly is critical for interoperability. Major marketplaces like OpenSea and LooksRare query this function. A common practice is to have the function revert or return zero values for tokens where royalties are not applicable, providing clear on-chain signaling. Developers must also consider gas efficiency, as this function is called during sales transactions. More advanced implementations may use bit packing to store the recipient and basis points in a single storage slot or employ upgradeable proxy patterns to allow royalty parameters to be adjusted post-deployment, balancing immutability with practical business needs.
Ecosystem Usage & Adoption
The RoyaltyInfo interface, defined by ERC-2981, is the standard method for on-chain royalty information. It enables smart contracts to programmatically declare how to pay royalties to creators for secondary sales of NFTs.
Core Technical Specification
The interface defines a single, mandatory function: royaltyInfo(uint256 tokenId, uint256 salePrice). This function returns two values: the recipient address for the royalty payment and the royalty amount to be paid, calculated from the salePrice. This provides a universal, machine-readable way for marketplaces to query and execute payments.
Marketplace Integration
Major NFT marketplaces like OpenSea, Blur, and LooksRare have integrated ERC-2981 support. When a sale occurs, their smart contracts call the royaltyInfo function on the NFT contract to determine the correct payment split, automatically routing funds to the creator. This has become the primary on-chain enforcement mechanism for creator royalties.
Implementation Patterns
Royalty logic can be implemented in several ways:
- Global Default: A single recipient and percentage applied to all tokens in the collection.
- Token-Specific: Royalties can be set per token ID, allowing for unique terms for individual NFTs.
- Tiered Systems: Logic can be added to calculate royalties based on sale price tiers or other on-chain conditions.
Interaction with ERC-721 & ERC-1155
ERC-2981 is a supplementary standard designed to be added to existing NFT contracts. It is commonly implemented alongside ERC-721 (for unique tokens) or ERC-1155 (for semi-fungible tokens). The royaltyInfo function is agnostic to the base token standard, querying only by tokenId and salePrice.
Limitations and Considerations
While a critical standard, ERC-2981 has known constraints:
- Optional Enforcement: It provides information but does not force payment; marketplace compliance is required.
- Off-Chain Sales: Does not apply to sales executed outside integrated platforms.
- Gas Costs: The logic executed in
royaltyInfomust be gas-efficient to avoid failed transactions during sales.
Security & Implementation Considerations
The RoyaltyInfo interface standardizes on-chain royalty payments for NFTs, but its implementation requires careful attention to security, gas optimization, and protocol compatibility.
Royalty Enforcement & Trust Assumptions
The RoyaltyInfo interface is a standard, not an enforcement mechanism. It defines a function (royaltyInfo(uint256 tokenId, uint256 salePrice)) that returns a recipient address and royalty amount. Marketplaces must voluntarily call this function and forward payments. Security depends on marketplace compliance, not the interface itself. Implementations should be aware of the trust assumptions between creators, marketplaces, and collectors.
Gas Optimization for Lookups
Frequent on-chain royalty lookups can be gas-intensive. Key optimization strategies include:
- Caching royalty recipients in a mapping to avoid repeated
SSTOREoperations for new tokens. - Using bit packing to store royalty numerators (e.g., basis points) and recipient addresses in a single storage slot where possible.
- Implementing an upgradeable proxy pattern for the royalty logic to allow for future gas optimizations without migrating the NFT contract.
- Considering EIP-2981's optional
supportsInterfacecheck to allow marketplaces to verify support before calling.
Handling Malformed Return Data
A secure marketplace implementation must defensively handle the data returned by royaltyInfo. Critical checks include:
- Validating the recipient address is not
address(0). - Ensuring the royalty amount does not exceed the sale price (e.g.,
royaltyAmount <= salePrice). - Accounting for integer overflow/underflow in the calculation (
salePrice * royaltyRate / 10000). - Implementing a reasonable gas limit for the external call to prevent denial-of-service attacks via expensive logic in the NFT contract's royalty function.
Upgradability and Admin Controls
Contracts implementing RoyaltyInfo often require mechanisms to update royalty parameters. This introduces centralization and security risks:
- Use a multi-signature wallet or timelock controller for the admin address that can update royalty recipients or rates.
- Clearly define and emit events for all royalty parameter changes for transparency.
- Consider immutable royalty schemes for high-value collections to eliminate admin key risk, trading flexibility for absolute security.
- For upgradeable contracts, ensure the royalty logic is part of the upgradeable implementation, not the proxy storage layout.
Cross-Protocol Compatibility (ERC-721 vs ERC-1155)
The RoyaltyInfo interface (EIP-2981) is designed for both ERC-721 and ERC-1155 tokens. Implementation differences include:
- For ERC-1155, the
tokenIdparameter is crucial as a single contract can have multiple token types with different royalty settings. - The
salePriceparameter should be interpreted in the native token of the transaction (e.g., ETH, MATIC). Marketplaces dealing in ERC-20s must handle conversion. - Contracts must correctly implement the ERC-165
supportsInterfacecheck fortype(IERC2981).interfaceIdto be detected by marketplaces.
Front-running and Oracle Manipulation
While the interface itself is not susceptible, the ecosystem around it has vulnerabilities:
- Oracle-derived sale prices: If the
salePricefed toroyaltyInfocomes from an oracle, it must be resistant to manipulation (e.g., TWAPs vs. spot prices). - Royalty sniping: A malicious actor could front-run a sale transaction to temporarily change the royalty recipient if admin functions are insecure. Timelocks mitigate this.
- Division truncation: The calculation
salePrice * royaltyBasisPoints / 10000uses integer division, which truncates. Design should ensure this does not lead to systematic underpayment over many transactions.
Comparison: On-Chain vs. Off-Chain Royalty Mechanisms
A technical comparison of how royalty logic and payment data are stored and enforced.
| Feature | On-Chain Enforcement | Off-Chain Enforcement |
|---|---|---|
Logic Location | Smart contract (e.g., RoyaltyInfo) | Centralized server or marketplace policy |
Payment Data Source | Immutable blockchain state | Private database or API |
Enforcement Guarantee | Programmatic, trustless | Policy-based, requires trust |
Gas Cost Impact | Higher (logic executes on-chain) | None for the blockchain |
Upgrade Flexibility | Requires contract migration | Instant, centralized update |
Censorship Resistance | High | Low |
Interoperability | Universal for compliant contracts | Marketplace-specific |
Example Standard | EIP-2981 (RoyaltyInfo) | Platform Terms of Service |
RoyaltyInfo Interface
The RoyaltyInfo interface is the core technical specification within the ERC-2981 standard that defines a universal method for smart contracts to report royalty payment details.
The RoyaltyInfo interface is a function signature, royaltyInfo(uint256 tokenId, uint256 salePrice), that returns a recipient address and a royalty amount. This simple, gas-efficient design allows any marketplace or smart contract to query an NFT contract to determine where and how much to pay in royalties for a secondary sale. By standardizing this single function, ERC-2981 creates a predictable, on-chain mechanism for royalty enforcement that is independent of any specific marketplace's implementation.
Prior to ERC-2981, royalty payment was a fragmented landscape where each marketplace implemented its own proprietary system, often relying on off-chain metadata. This led to inconsistencies, missed payments, and forced creators to manually register their works on each platform. The RoyaltyInfo interface solves this by moving the royalty logic directly into the NFT's smart contract, making it a verifiable and immutable part of the token itself. This shift represents a fundamental evolution from platform-dependent policies to contract-enforced creator rights.
The interface's parameters are intentionally generic. The tokenId allows for per-token royalty configurations (e.g., different royalties for different pieces in a collection), while the salePrice enables the calculation of a royalty amount as a percentage of the current transaction. The function returns two values: the receiver address (which can be a simple EOA, a multi-sig wallet, or a complex payment splitter contract) and the royaltyAmount (typically calculated as (salePrice * royaltyBasisPoints) / 10000). This flexibility supports a wide range of business models and payout structures.
Widespread adoption of the RoyaltyInfo interface by marketplaces and NFT projects has established it as the de facto standard for on-chain royalties. Its success has also spurred further innovation in the broader royalty landscape, including the development of more complex modular royalty systems (like EIP-6110), which can delegate logic to separate contracts, and the integration of royalty enforcement directly into core token standards like ERC-721C. The interface remains the foundational layer upon which these more advanced systems are built.
Frequently Asked Questions (FAQ)
Common developer questions about the ERC-2981 RoyaltyInfo interface, which standardizes royalty payments for NFTs across marketplaces and applications.
The RoyaltyInfo interface is a core component of the ERC-2981 standard that defines a smart contract function, royaltyInfo(), to programmatically report royalty payment details for a given NFT. This function returns the recipient address and the royalty amount for a specified sale price, enabling any marketplace or application to discover and pay royalties automatically. It solves the pre-2021 problem where royalties were enforced off-chain or via custom, incompatible implementations, leading to widespread non-payment. By providing a single, universal function signature, it creates a predictable on-chain royalty standard for ERC-721 and ERC-1155 tokens.
Get In Touch
today.
Our experts will offer a free quote and a 30min call to discuss your project.