Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers ERC-6786, which proposes a way to record and retrieve the royalties received by creators using ERC-2981.
This explanation translates, summarizes and expands on the original proposal.
As of October 18, 2023, ERC-6786 was at the Draft stage.
I have also written about other ERCs.
Overview
This standard allows anyone to pay royalties for a specific NFT and records the amount paid. Every payment made through the standard increases the cumulative total, making the information publicly available.
Motivation
The standard arose from the need to establish incentives for NFT creators when many NFT trading platforms either provided no mechanism for paying creators on sales and resales or made royalty payments difficult to track.
The contract provides a way to calculate the royalties a creator has received for a particular NFT. This is useful for organizing royalty information and classifying NFTs into different categories. The concept of royalty debt also aims to identify unpaid royalties from NFT trades on marketplaces that do not support royalties and provide a way to pay them.
While many NFT trading platforms simplify royalty payments or take a centralized approach, this proposal seeks to give anyone a way to pay NFT creators directly. It provides a means of supporting their work.
The standard strengthens incentives for creators in the NFT ecosystem and aims to make royalty payments more transparent and efficient.
Specification
All contracts compliant with ERC-6786 must implement the following interface.
Contract interface
// @title Royalty Debt Registry
/// Note: the ERC-165 identifier for this interface is 0x253b27b0
interface IERC6786 {
// Logged when royalties were paid for a NFT
/// @notice Emitted when royalties are paid for the NFT with address tokenAddress and id tokenId
event RoyaltiesPaid(address indexed tokenAddress, uint256 indexed tokenId, uint256 amount);
/// @notice sends msg.value to the creator of a NFT
/// @dev Reverts if there are no on-chain informations about the creator
/// @param tokenAddress The address of NFT contract
/// @param tokenId The NFT id
function payRoyalties(address tokenAddress, uint256 tokenId) external payable;
/// @notice Get the amount of royalties which was paid for a NFT
/// @dev
/// @param tokenAddress The address of NFT contract
/// @param tokenId The NFT id
/// @return The amount of royalties paid for the NFT
function getPaidRoyalties(address tokenAddress, uint256 tokenId) external view returns (uint256);
}The following rules govern the design and implementation of the contract.
-
All functions declared as
viewmay be implemented as eitherpureorview.- Functions that perform read-only operations without modifying external state may be implemented as
pureorview, as appropriate. - This makes it explicit that these functions do not modify contract state.
- Functions that perform read-only operations without modifying external state may be implemented as
-
The
payRoyaltiesfunction may be implemented aspublicorexternal.- Because
payRoyaltiespays royalties and can be called from outside the contract, either visibility is permitted. - This allows external entities to use the function.
- Because
-
A successful call to
payRoyaltiesmust emit theRoyaltiesPaidevent.- The event must be emitted to indicate that royalties have been paid.
- It helps notify other actors that the transaction completed successfully.
-
The
supportsInterfacefunction must returntruewhen called with0x253b27b0.- The specified interface identifier (
0x253b27b0) must produce a return value oftrue. - This function is used to determine whether a contract supports a particular interface or capability.
- The specified interface identifier (
Following these rules makes the contract's design and implementation transparent and facilitates interoperability with other contracts.
Additional notes
Payments can be made in the chain's native currency, making it straightforward to track the amount of royalties paid. The intention is to make this information public so anyone can verify whether a creator has received royalties. This is particularly useful for off-market deals and marketplaces that do not support royalties.
Anyone, including ordinary users who do not own the NFT, can call the payment function at any time to support its creator. The standard also provides a publicly accessible way to check the royalties paid for any token.
ERC-2981 can be used to obtain on-chain information about the creator, although other on-chain methods may also be used to obtain the creator's address.
See the following article for more on ERC-2981.
[ERC2981] Can NFT royalties be enforced? How ERC-2981 works
Payments are made in the native currency, and royalty information is publicly available. Anyone can use the payment function to support creators. On-chain methods such as ERC-2981 can also be used to obtain the creator's address.
Backward compatibility
This ERC does not introduce backward compatibility requirements.
Tests
The test code is available here.
https://eips.ethereum.org/assets/eip-6786/test/ERC6786.test.js
Reference implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "./IERC6786.sol";
import "./utils/IERC2981.sol";
contract ERC6786 is IERC6786, ERC165 {
//Mapping from token (address and id) to the amount of paid royalties
mapping(address => mapping(uint256 => uint256)) private _paidRoyalties;
/*
* bytes4(keccak256('payRoyalties(address,uint256)')) == 0xf511f0e9
* bytes4(keccak256('getPaidRoyalties(address,uint256)')) == 0xd02ad759
*
* => 0xf511f0e9 ^ 0xd02ad759 == 0x253b27b0
*/
bytes4 private constant _INTERFACE_ID_ERC6786 = 0x253b27b0;
/*
* bytes4(keccak256('royaltyInfo(uint256,uint256)')) == 0x2a55205a
*/
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
/// @notice This is thrown when there is no creator related information
/// @param tokenAddress -> the address of the contract
/// @param tokenId -> the id of the NFT
error CreatorError(address tokenAddress, uint256 tokenId);
/// @notice This is thrown when the payment fails
/// @param creator -> the address of the creator
/// @param amount -> the amount to pay
error PaymentError(address creator, uint256 amount);
function checkRoyalties(address _contract) internal view returns (bool) {
(bool success) = IERC165(_contract).supportsInterface(_INTERFACE_ID_ERC2981);
return success;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IERC6786).interfaceId ||
super.supportsInterface(interfaceId);
}
function payRoyalties(address tokenAddress, uint256 tokenId) external override payable {
if (!checkRoyalties(tokenAddress)) {
revert CreatorError(tokenAddress, tokenId);
}
(address creator,) = IERC2981(tokenAddress).royaltyInfo(tokenId, 0);
(bool success,) = payable(creator).call{value : msg.value}("");
if(!success) {
revert PaymentError(creator, msg.value);
}
_paidRoyalties[tokenAddress][tokenId] += msg.value;
emit RoyaltiesPaid(tokenAddress, tokenId, msg.value);
}
function getPaidRoyalties(address tokenAddress, uint256 tokenId) external view override returns (uint256) {
return _paidRoyalties[tokenAddress][tokenId];
}
}_paidRoyalties
// Mapping from token (address and id) to the amount of paid royalties
mapping(address => mapping(uint256 => uint256)) private _paidRoyalties;Overview A nested mapping that tracks the amount of royalties paid for a token, identified by its contract address and ID.
Details
- It records the royalties paid for a particular NFT.
- The mapping tracks the amount using the NFT's contract address and token ID.
_paidRoyaltiesis declared private, so it is directly accessible only within the contract.
Parameters
address- NFT contract address.
uint256- NFT token ID.
uint256- Amount of royalties paid.
_INTERFACE_ID_ERC6786
/*
* bytes4(keccak256('payRoyalties(address,uint256)')) == 0xf511f0e9
* bytes4(keccak256('getPaidRoyalties(address,uint256)')) == 0xd02ad759
*
* => 0xf511f0e9 ^ 0xd02ad759 == 0x253b27b0
*/
bytes4 private constant _INTERFACE_ID_ERC6786 = 0x253b27b0;Overview A variable representing the ERC-6786 interface identifier.
Details
_INTERFACE_ID_ERC6786holds the identifier derived from the function selectors used in the ERC-6786 interface.- The identifier incorporates
payRoyaltiesandgetPaidRoyaltiesand is used to indicate support for the interface.
_INTERFACE_ID_ERC2981
/*
* bytes4(keccak256('royaltyInfo(uint256,uint256)')) == 0x2a55205a
*/
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;Overview A variable representing the ERC-2981 interface identifier.
Details
_INTERFACE_ID_ERC2981holds the identifier derived from the function selector used in the ERC-2981 interface.- It corresponds to
royaltyInfo, which is used to retrieve royalty information for a token.
CreatorError
/// @notice This is thrown when there is no creator related information
/// @param tokenAddress -> the address of the contract
/// @param tokenId -> the id of the NFT
error CreatorError(address tokenAddress, uint256 tokenId);Overview An error raised when creator-related information is unavailable.
Details
CreatorErroris thrown when information about the creator is missing.- The error includes the token contract address and ID.
Parameters
tokenAddress- Contract address.
tokenId- NFT token ID.
PaymentError
/// @notice This is thrown when the payment fails
/// @param creator -> the address of the creator
/// @param amount -> the amount to pay
error PaymentError(address creator, uint256 amount);Overview An error raised when a payment fails.
Details
PaymentErroris thrown when a payment cannot be completed successfully.- The error includes the creator's address and the payment amount.
Parameters
creator- Creator's address.
amount- Payment amount.
checkRoyalties
function checkRoyalties(address _contract) internal view returns (bool) {
(bool success) = IERC165(_contract).supportsInterface(_INTERFACE_ID_ERC2981);
return success;
}Overview Checks whether a specified contract supports ERC-2981.
Details
- This internal function checks whether the contract at the specified address supports ERC-2981.
IERC165(_contract).supportsInterface(_INTERFACE_ID_ERC2981)returnstrueif the specified contract reports support for ERC-2981.- The function returns a Boolean indicating whether ERC-2981 is supported.
Parameters
_contract- Address of the contract to check.
Return value
booltrueif the contract supports ERC-2981; otherwisefalse.
supportsInterface
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == type(IERC6786).interfaceId ||
super.supportsInterface(interfaceId);
}Overview Handles interface support for ERC-6786 and the parent class.
Details
supportsInterfacehandles the interfaces supported by ERC-6786 and its parent class, returning whether the requested interface is supported.- It checks the ERC-6786 interface ID and the interfaces supported by the parent class, returning
trueon a match.
Parameters
interfaceId- Interface ID to check.
Return value
booltrueif the requested interface is supported; otherwisefalse.
payRoyalties
function payRoyalties(address tokenAddress, uint256 tokenId) external override payable {
if (!checkRoyalties(tokenAddress)) {
revert CreatorError(tokenAddress, tokenId);
}
(address creator,) = IERC2981(tokenAddress).royaltyInfo(tokenId, 0);
(bool success,) = payable(creator).call{value : msg.value}("");
if(!success) {
revert PaymentError(creator, msg.value);
}
_paidRoyalties[tokenAddress][tokenId] += msg.value;
emit RoyaltiesPaid(tokenAddress, tokenId, msg.value);
}Overview The royalty payment entry point, used to pay royalties for a specified NFT.
Details
payRoyaltiesis an external function that pays royalties for the specified token contract and token ID.- It first calls
checkRoyaltiesto determine whether the specified token contract supports ERC-2981. - It then obtains the creator's address from the specified contract and token ID.
- It transfers the payment to the creator using
payable(creator).call{value : msg.value}(""). - If the payment fails, the function throws an error.
- After a successful payment, it records the amount of royalties paid and emits the
RoyaltiesPaidevent.
Parameters
tokenAddress- NFT contract address.
tokenId- NFT token ID.
getPaidRoyalties
function getPaidRoyalties(address tokenAddress, uint256 tokenId) external view override returns (uint256) {
return _paidRoyalties[tokenAddress][tokenId];
}Overview Returns the amount of royalties paid for a specified NFT.
Details
getPaidRoyaltiesretrieves the royalties paid for the specified token contract address and token ID.- It looks up the corresponding entry in the
_paidRoyaltiesmapping and returns the royalty amount.
Parameters
tokenAddress- NFT contract address.
tokenId- NFT token ID.
Return value
uint256- Amount of royalties paid.
Security considerations
The proposal lists no security considerations directly related to implementing this standard.
Reference
Otniel Nicola (@OT-kthd), Bogdan Popa (@BogdanKTHD), "ERC-6786: Registry for royalties payment for NFTs [DRAFT]," Ethereum Improvement Proposals, no. 6786, March 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6786.
Conclusion
This article covered ERC-6786, a proposed standard for recording and retrieving the royalties received by creators using ERC-2981.
If you have questions, feel free to contact me via Twitter DM.
You can also find my writing on other platforms.


