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 ERC721C, an extension proposing a mechanism for enforcing on-chain royalties.
What is ERC721C?
ERC721C extends NFT transfer validation so that creators can enforce policies intended to protect their royalties from secondary sales.
For more about royalties, see the following article.
[ERC2981] Understanding the NFT Royalty Standard
The original NFT standards, ERC721 and ERC1155, do not specify a royalty mechanism. NFT marketplaces such as OpenSea therefore introduced their own mechanisms for returning a portion of NFT sale proceeds to creators. These were marketplace-level arrangements rather than universally enforced on-chain royalty requirements. ERC2981 was proposed to address the lack of a common interface. ERC2981 provides a standardized on-chain interface for reporting royalty information, rather than enforcing royalty payment itself.
For more about ERC2981, see the following article.
[ERC2981] Understanding the NFT Royalty Standard
However, ERC2981 lacks a mechanism for forcing every transaction to pay royalties.
For example, creators may not receive royalties in the following situations.
- Marketplaces that do not collect royalties
- A marketplace that does not implement ERC2981 or collect creator royalties cannot enforce their payment through ERC2981 alone.
- Peer-to-peer transactions
- Royalties cannot be universally enforced through ERC2981 when people trade directly without a marketplace.
- For example, payment in ETH and transfer of the NFT may occur separately, without a marketplace collecting a royalty.
ERC721C and ERC1155C were introduced in response to this limitation.
ERC721C and ERC1155C extend existing NFT standards with transfer validation, retaining their standard interfaces while allowing additional royalty-related restrictions. Creators can use these extensions to allow interactions with contracts and applications that they deem trustworthy and useful. Compatibility with existing NFT interfaces also facilitates integration with existing NFT tooling and the creation of new collections. Creators determine the royalty configuration and can use transfer policies designed to protect compensation for their work.
For more about ERC721, see the following resource.
For more about ERC1155, see the following resource.
ERC721C in detail
The following sections explain the ERC721C implementation.
The implementation guide describes the following setup steps.
- Inherit the relevant contracts.
- Customize the contract.
- Deploy the ERC721C collection.
- Configure the security policy.
- Configure it in the constructor, which runs once at deployment, or call
setToDefaultSecurityPolicy. - This configures ERC721C to use the Creator Token Transfer Validator contract and apply a transfer security policy.
- Configure it in the constructor, which runs once at deployment, or call
- Complete the setup.
- The configured collection can now apply its transfer security policy when tokens are transferred.
- Subject to access control, developers can update the transfer security policy and whitelists, or replace the Creator Token Transfer Validator with a custom implementation.
import "../../contracts/erc721c/ERC721C.sol";
contract MyERC721CCollection is ERC721C {
constructor() ERC721C("Name of My Collection", "SYMBOL") {
setToDefaultSecurityPolicy();
}
// TODO: Implement/Override base uri
// TODO: Implement public minting function(s)
// TODO: Implement EIP-2981 Royalties
// TODO: Your other contract features, if any
}Operator Whitelists
- An operator whitelist lists addresses permitted to perform operator actions such as NFT transfers.
- Its authorized administrator can add or remove addresses.
- Depending on the selected policy, operator actions are restricted to listed addresses.
Context Receiver Allow Lists
- A permitted contract receiver list identifies contracts that may receive tokens under policies restricting contract recipients.
- Its authorized administrator can add or remove addresses.
Sets Transfer Security Level Of Collections
- Sets the transfer security level for a token collection.
- An administrator can select a stricter security level to restrict unwanted transfers.
Sets Operator Whitelist Of Collections
- Assigns an operator whitelist to a specified collection.
- The administrator can restrict which operators may transfer tokens in that collection.
Sets Contract Receiver Allow List of Collections
- Assigns a permitted contract receiver list to a specified collection.
- The administrator can control which contracts may receive tokens under the selected policy.
Transfer security policy
Predefined transfer security levels
- A level specifying the security requirements for token transfers.
- Different levels impose different combinations of restrictions.
Operator whitelist ID
- Identifies the whitelist that controls which operators may perform token transfers.
Permitted contract receiver list ID
- Identifies the list of contracts permitted to receive tokens.
- This optional mechanism allows specified contracts to receive tokens despite applicable receiver restrictions.
Transfer security levels
The transfer security level within the transfer security policy has seven levels, as shown in the preceding diagram. The descriptions below assume a configured, nonempty operator whitelist where relevant; the implementation also permits explicitly approved contract recipients.
Level 0
- Caller constraints
- None.
- Receiver constraints
- None.
- Description
- The least restrictive level: the validator imposes no additional caller or receiver constraints. Ordinary ERC721 authorization still applies.
Level 1
- Caller constraints
- OperatorWhitelistEnableOTC
- Receiver constraints
- None.
- Description
- The caller must be a whitelisted operator or the token owner making a direct transfer. There are no additional receiver restrictions.
Level 2
- Caller constraints
- OperatorWhitelistDisableOTC
- Receiver constraints
- None.
- Description
- With a nonempty whitelist, the caller must be whitelisted; non-whitelisted direct transfers are not allowed. There are no additional receiver restrictions.
Level 3
- Caller constraints
- OperatorWhitelistEnableOTC
- Receiver constraints
- NoCode
- Description
- Whitelisted operators and direct owner transfers are allowed. A receiver must have no deployed code or be an explicitly permitted contract receiver.
Level 4
- Caller constraints
- OperatorWhitelistEnableOTC
- Receiver constraints
- EOA
- Description
- Whitelisted operators and direct owner transfers are allowed. A receiver must be a verified externally owned account (EOA) or an explicitly permitted contract receiver.
Level 5
- Caller constraints
- OperatorWhitelistDisableOTC
- Receiver constraints
- NoCode
- Description
- With a nonempty whitelist, the caller must be whitelisted; non-whitelisted direct transfers are not allowed.
- A receiver must have no deployed code or be an explicitly permitted contract receiver.
Level 6
- Caller constraints
- OperatorWhitelistDisableOTC
- Receiver constraints
- EOA
- Description
- With a nonempty whitelist, the caller must be whitelisted; non-whitelisted direct transfers are not allowed.
- A receiver must be a verified EOA or an explicitly permitted contract receiver.
OTC stands for Over-The-Counter, generally referring to trades conducted directly rather than through an exchange. In this proposal, it refers to direct token transfers or trades.
ERC721C implementations
The following sections explain the ERC721C implementation. ERC721C can be combined with ERC2981 to build new types of programmable royalty contracts. For example, creators can share royalties with communities, partners, or affiliates.
Basic royalties
In the simplest form of programmable royalties, the contract owner configures default collection royalties or token-specific royalty settings. This allows the royalty percentage and recipient of each token's sale royalties to be customized.
abstract contract BasicRoyalties is ERC2981 {
event DefaultRoyaltySet(address indexed receiver, uint96 feeNumerator);
event TokenRoyaltySet(uint256 indexed tokenId, address indexed receiver, uint96 feeNumerator);
constructor(address receiver, uint96 feeNumerator) {
_setDefaultRoyalty(receiver, feeNumerator);
}
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual override {
super._setDefaultRoyalty(receiver, feeNumerator);
emit DefaultRoyaltySet(receiver, feeNumerator);
}
function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual override {
super._setTokenRoyalty(tokenId, receiver, feeNumerator);
emit TokenRoyaltySet(tokenId, receiver, feeNumerator);
}
}Minter-only royalties
Allocate 100% of the royalty payment to the original minter of an individual token. The royalty amount cannot be changed in this example. Depending on the configuration, however, the minter may be allowed to set their own royalty rate.
abstract contract ImmutableMinterRoyalties is IERC2981, ERC165 {
error ImmutableMinterRoyalties__MinterCannotBeZeroAddress();
error ImmutableMinterRoyalties__MinterHasAlreadyBeenAssignedToTokenId();
error ImmutableMinterRoyalties__RoyaltyFeeWillExceedSalePrice();
uint256 public constant FEE_DENOMINATOR = 10_000;
uint256 public immutable royaltyFeeNumerator;
mapping (uint256 => address) private _minters;
constructor(uint256 royaltyFeeNumerator_) {
if(royaltyFeeNumerator_ > FEE_DENOMINATOR) {
revert ImmutableMinterRoyalties__RoyaltyFeeWillExceedSalePrice();
}
royaltyFeeNumerator = royaltyFeeNumerator_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view override returns (address receiver, uint256 royaltyAmount) {
return (_minters[tokenId], (salePrice * royaltyFeeNumerator) / FEE_DENOMINATOR);
}
function _onMinted(address minter, uint256 tokenId) internal {
if (minter == address(0)) {
revert ImmutableMinterRoyalties__MinterCannotBeZeroAddress();
}
if (_minters[tokenId] != address(0)) {
revert ImmutableMinterRoyalties__MinterHasAlreadyBeenAssignedToTokenId();
}
_minters[tokenId] = minter;
}
function _onBurned(uint256 tokenId) internal {
delete _minters[tokenId];
}
}Shared royalties
Pay royalties to multiple addresses to share them between the creator and the token's minter.
abstract contract MinterCreatorSharedRoyalties is IERC2981, ERC165 {
error MinterCreatorSharedRoyalties__RoyaltyFeeWillExceedSalePrice();
error MinterCreatorSharedRoyalties__MinterCannotBeZeroAddress();
error MinterCreatorSharedRoyalties__MinterHasAlreadyBeenAssignedToTokenId();
error MinterCreatorSharedRoyalties__PaymentSplitterDoesNotExistForSpecifiedTokenId();
enum ReleaseTo {
Minter,
Creator
}
uint256 public constant FEE_DENOMINATOR = 10_000;
uint256 public immutable royaltyFeeNumerator;
uint256 public immutable minterShares;
uint256 public immutable creatorShares;
address public immutable creator;
mapping (uint256 => address) private _minters;
mapping (uint256 => address) private _paymentSplitters;
mapping (address => address[]) private _minterPaymentSplitters;
constructor(uint256 royaltyFeeNumerator_, uint256 minterShares_, uint256 creatorShares_, address creator_) {
if(royaltyFeeNumerator_ > FEE_DENOMINATOR) {
revert MinterCreatorSharedRoyalties__RoyaltyFeeWillExceedSalePrice();
}
royaltyFeeNumerator = royaltyFeeNumerator_;
minterShares = minterShares_;
creatorShares = creatorShares_;
creator = creator_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view override returns (address, uint256) {
return (_paymentSplitters[tokenId], (salePrice * royaltyFeeNumerator) / FEE_DENOMINATOR);
}
function minterOf(uint256 tokenId) external view returns (address) {
return _minters[tokenId];
}
function paymentSplitterOf(uint256 tokenId) external view returns (address) {
return _paymentSplitters[tokenId];
}
function paymentSplittersOfMinter(address minter) external view returns (address[] memory) {
return _minterPaymentSplitters[minter];
}
function releasableNativeFunds(uint256 tokenId, ReleaseTo releaseTo) external view returns (uint256) {
PaymentSplitter paymentSplitter = _getPaymentSplitterForTokenOrRevert(tokenId);
if (releaseTo == ReleaseTo.Minter) {
return paymentSplitter.releasable(payable(_minters[tokenId]));
} else {
return paymentSplitter.releasable(payable(creator));
}
}
function releasableERC20Funds(uint256 tokenId, address coin, ReleaseTo releaseTo) external view returns (uint256) {
PaymentSplitter paymentSplitter = _getPaymentSplitterForTokenOrRevert(tokenId);
if (releaseTo == ReleaseTo.Minter) {
return paymentSplitter.releasable(IERC20(coin), _minters[tokenId]);
} else {
return paymentSplitter.releasable(IERC20(coin), creator);
}
}
function releaseNativeFunds(uint256 tokenId, ReleaseTo releaseTo) external {
PaymentSplitter paymentSplitter = _getPaymentSplitterForTokenOrRevert(tokenId);
if (releaseTo == ReleaseTo.Minter) {
paymentSplitter.release(payable(_minters[tokenId]));
} else {
paymentSplitter.release(payable(creator));
}
}
function releaseERC20Funds(uint256 tokenId, address coin, ReleaseTo releaseTo) external {
PaymentSplitter paymentSplitter = _getPaymentSplitterForTokenOrRevert(tokenId);
if(releaseTo == ReleaseTo.Minter) {
paymentSplitter.release(IERC20(coin), _minters[tokenId]);
} else {
paymentSplitter.release(IERC20(coin), creator);
}
}
function _onMinted(address minter, uint256 tokenId) internal {
if (minter == address(0)) {
revert MinterCreatorSharedRoyalties__MinterCannotBeZeroAddress();
}
if (_minters[tokenId] != address(0)) {
revert MinterCreatorSharedRoyalties__MinterHasAlreadyBeenAssignedToTokenId();
}
address paymentSplitter = _createPaymentSplitter(minter);
_paymentSplitters[tokenId] = paymentSplitter;
_minterPaymentSplitters[minter].push(paymentSplitter);
_minters[tokenId] = minter;
}
function _onBurned(uint256 tokenId) internal {
delete _paymentSplitters[tokenId];
delete _minters[tokenId];
}
function _createPaymentSplitter(address minter) private returns (address) {
if (minter == creator) {
address[] memory payees = new address[](1);
payees[0] = creator;
uint256[] memory shares = new uint256[](1);
shares[0] = minterShares + creatorShares;
return address(new PaymentSplitter(payees, shares));
} else {
address[] memory payees = new address[](2);
payees[0] = minter;
payees[1] = creator;
uint256[] memory shares = new uint256[](2);
shares[0] = minterShares;
shares[1] = creatorShares;
return address(new PaymentSplitter(payees, shares));
}
}
function _getPaymentSplitterForTokenOrRevert(uint256 tokenId) private view returns (PaymentSplitter) {
address paymentSplitterForToken = _paymentSplitters[tokenId];
if(paymentSplitterForToken == address(0)) {
revert MinterCreatorSharedRoyalties__PaymentSplitterDoesNotExistForSpecifiedTokenId();
}
return PaymentSplitter(payable(paymentSplitterForToken));
}
}Transferable royalties
Use a secondary NFT to represent ownership of the royalty entitlement. The minter initially receives the royalty entitlement as an NFT, which can subsequently be transferred to another wallet.
interface ICloneableRoyaltyRightsERC721 is IERC721 {
function initializeAndBindToCollection() external;
function mint(address to, uint256 tokenId) external;
function burn(uint256 tokenId) external;
}
abstract contract MinterRoyaltiesReassignableRightsNFT is IERC2981, ERC165 {
error MinterRoyaltiesReassignableRightsNFT__MinterCannotBeZeroAddress();
error MinterRoyaltiesReassignableRightsNFT__RoyaltyFeeWillExceedSalePrice();
uint256 public constant FEE_DENOMINATOR = 10_000;
uint256 public immutable royaltyFeeNumerator;
ICloneableRoyaltyRightsERC721 public immutable royaltyRightsNFT;
constructor(uint256 royaltyFeeNumerator_, address royaltyRightsNFTReference_) {
if(royaltyFeeNumerator_ > FEE_DENOMINATOR) {
revert MinterRoyaltiesReassignableRightsNFT__RoyaltyFeeWillExceedSalePrice();
}
royaltyFeeNumerator = royaltyFeeNumerator_;
ICloneableRoyaltyRightsERC721 royaltyRightsNFT_ =
ICloneableRoyaltyRightsERC721(Clones.clone(royaltyRightsNFTReference_));
royaltyRightsNFT_.initializeAndBindToCollection();
royaltyRightsNFT = royaltyRightsNFT_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view override returns (address receiver, uint256 royaltyAmount) {
address rightsHolder = address(0);
try royaltyRightsNFT.ownerOf(tokenId) returns (address rightsTokenOwner) {
rightsHolder = rightsTokenOwner;
} catch {}
return (rightsHolder, (salePrice * royaltyFeeNumerator) / FEE_DENOMINATOR);
}
function _onMinted(address minter, uint256 tokenId) internal {
if (minter == address(0)) {
revert MinterRoyaltiesReassignableRightsNFT__MinterCannotBeZeroAddress();
}
royaltyRightsNFT.mint(minter, tokenId);
}
function _onBurned(uint256 tokenId) internal {
royaltyRightsNFT.burn(tokenId);
}
}
contract RoyaltyRightsNFT is ERC721, ICloneableRoyaltyRightsERC721 {
error RoyaltyRightsNFT__CollectionAlreadyInitialized();
error RoyaltyRightsNFT__OnlyBurnableFromCollection();
error RoyaltyRightsNFT__OnlyMintableFromCollection();
IERC721Metadata public collection;
constructor() ERC721("", "") {}
function initializeAndBindToCollection() external override {
if (address(collection) != address(0)) {
revert RoyaltyRightsNFT__CollectionAlreadyInitialized();
}
collection = IERC721Metadata(_msgSender());
}
function mint(address to, uint256 tokenId) external override {
if (_msgSender() != address(collection)) {
revert RoyaltyRightsNFT__OnlyMintableFromCollection();
}
_mint(to, tokenId);
}
function burn(uint256 tokenId) external override {
if (_msgSender() != address(collection)) {
revert RoyaltyRightsNFT__OnlyBurnableFromCollection();
}
_burn(tokenId);
}
function name() public view virtual override returns (string memory) {
return string(abi.encodePacked(collection.name(), " Royalty Rights"));
}
function symbol() public view virtual override returns (string memory) {
return string(abi.encodePacked(collection.symbol(), "RR"));
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
return collection.tokenURI(tokenId);
}
}Combining extensions
An ERC721C contract combining several extensions.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@limitbreak/creator-token-contracts/contracts
/erc721c/ERC721C.sol";
import "@limitbreak/creator-token-contracts/contracts
/programmable-royalties/ImmutableMinterRoyalties.sol";
contract ERC721CWithImmutableMinterRoyalties is ERC721C, ImmutableMinterRoyalties {
constructor(
uint256 royaltyFeeNumerator_,
string memory name_,
string memory symbol_)
ERC721C(name_, symbol_)
ImmutableMinterRoyalties(royaltyFeeNumerator_) {
setToDefaultSecurityPolicy();
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721C, ImmutableMinterRoyalties) returns (bool) {
return super.supportsInterface(interfaceId);
}
function mint(address to, uint256 tokenId) external {
_mint(to, tokenId);
}
function safeMint(address to, uint256 tokenId) external {
_safeMint(to, tokenId);
}
function burn(uint256 tokenId) external {
_burn(tokenId);
}
function _mint(address to, uint256 tokenId) internal virtual override {
_onMinted(to, tokenId);
super._mint(to, tokenId);
}
function _burn(uint256 tokenId) internal virtual override {
super._burn(tokenId);
_onBurned(tokenId);
}
}Reference implementation
Finally, examine the reference implementation.
ERC721C.sol
The following is the ERC721C contract.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../utils/CreatorTokenBase.sol";
import "../token/erc721/ERC721OpenZeppelin.sol";
/**
* @title ERC721C
* @author Limit Break, Inc.
* @notice Extends OpenZeppelin's ERC721 implementation with Creator Token functionality, which
* allows the contract owner to update the transfer validation logic by managing a security policy in
* an external transfer validation security policy registry. See {CreatorTokenTransferValidator}.
*/
abstract contract ERC721C is ERC721OpenZeppelin, CreatorTokenBase {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(ICreatorToken).interfaceId || super.supportsInterface(interfaceId);
}
/// @dev Ties the open-zeppelin _beforeTokenTransfer hook to more granular transfer validation logic
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
for (uint256 i = 0; i < batchSize;) {
_validateBeforeTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
/// @dev Ties the open-zeppelin _afterTokenTransfer hook to more granular transfer validation logic
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
for (uint256 i = 0; i < batchSize;) {
_validateAfterTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
}
/**
* @title ERC721CInitializable
* @author Limit Break, Inc.
* @notice Initializable implementation of ERC721C to allow for EIP-1167 proxy clones.
*/
abstract contract ERC721CInitializable is ERC721OpenZeppelinInitializable, CreatorTokenBase {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(ICreatorToken).interfaceId || super.supportsInterface(interfaceId);
}
/// @dev Ties the open-zeppelin _beforeTokenTransfer hook to more granular transfer validation logic
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
for (uint256 i = 0; i < batchSize;) {
_validateBeforeTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
/// @dev Ties the open-zeppelin _afterTokenTransfer hook to more granular transfer validation logic
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize) internal virtual override {
for (uint256 i = 0; i < batchSize;) {
_validateAfterTransfer(from, to, firstTokenId + i);
unchecked {
++i;
}
}
}
}The implementation overrides _beforeTokenTransfer and _afterTokenTransfer, which are invoked around token transfers, to call the following functions for each applicable operation.
_validateAfterTransfer(from, to, firstTokenId + i);These functions are implemented as shown below.
_validateBeforeTransfer
function _validateBeforeTransfer(address from, address to, uint256 tokenId) internal virtual {
bool fromZeroAddress = from == address(0);
bool toZeroAddress = to == address(0);
if(fromZeroAddress && toZeroAddress) {
revert ShouldNotMintToBurnAddress();
} else if(fromZeroAddress) {
_preValidateMint(_msgSender(), to, tokenId, msg.value);
} else if(toZeroAddress) {
_preValidateBurn(_msgSender(), from, tokenId, msg.value);
} else {
_preValidateTransfer(_msgSender(), from, to, tokenId, msg.value);
}
}Overview
A function that derived contracts must call from _beforeTokenTransfer to access more granular validation hooks.
Details
- Executes before a token transfer and performs validation specific to the operation.
- If both the source and destination are the zero address, minting to the burn address is disallowed and the function reverts with
ShouldNotMintToBurnAddress. - If the source is the zero address and the destination is nonzero, perform pre-mint validation.
- If the source is nonzero and the destination is the zero address, perform pre-burn validation.
- If both addresses are nonzero, perform ordinary pre-transfer validation.
Parameters
from- Source address.
to- Destination address.
tokenId- Token ID.
_validateAfterTransfer
function _validateAfterTransfer(address from, address to, uint256 tokenId) internal virtual {
bool fromZeroAddress = from == address(0);
bool toZeroAddress = to == address(0);
if(fromZeroAddress && toZeroAddress) {
revert ShouldNotMintToBurnAddress();
} else if(fromZeroAddress) {
_postValidateMint(_msgSender(), to, tokenId, msg.value);
} else if(toZeroAddress) {
_postValidateBurn(_msgSender(), from, tokenId, msg.value);
} else {
_postValidateTransfer(_msgSender(), from, to, tokenId, msg.value);
}
}Overview
A function that derived contracts must call from _afterTokenTransfer to access more granular validation hooks.
Details
- Executes after a token transfer and performs validation specific to the completed operation.
- If both the source and destination are the zero address, minting to the burn address is disallowed and the function reverts with
ShouldNotMintToBurnAddress. - If the source is the zero address and the destination is nonzero, perform post-mint validation.
- If the source is nonzero and the destination is the zero address, perform post-burn validation.
- If both addresses are nonzero, perform ordinary post-transfer validation.
Parameters
from- Source address.
to- Destination address.
tokenId- Token ID.
The functions invoked after these conditional checks can be customized individually, as shown below.
/// @dev Optional validation hook that fires before a mint
function _preValidateMint(address caller, address to, uint256 tokenId, uint256 value) internal virtual {}
/// @dev Optional validation hook that fires after a mint
function _postValidateMint(address caller, address to, uint256 tokenId, uint256 value) internal virtual {}
/// @dev Optional validation hook that fires before a burn
function _preValidateBurn(address caller, address from, uint256 tokenId, uint256 value) internal virtual {}
/// @dev Optional validation hook that fires after a burn
function _postValidateBurn(address caller, address from, uint256 tokenId, uint256 value) internal virtual {}
/// @dev Optional validation hook that fires before a transfer
function _preValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 value) internal virtual {}
/// @dev Optional validation hook that fires after a transfer
function _postValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 value) internal virtual {}ERC721OpenZeppelin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../../access/OwnablePermissions.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
abstract contract ERC721OpenZeppelinBase is ERC721 {
// Token name
string internal _contractName;
// Token symbol
string internal _contractSymbol;
function name() public view virtual override returns (string memory) {
return _contractName;
}
function symbol() public view virtual override returns (string memory) {
return _contractSymbol;
}
function _setNameAndSymbol(string memory name_, string memory symbol_) internal {
_contractName = name_;
_contractSymbol = symbol_;
}
}
abstract contract ERC721OpenZeppelin is ERC721OpenZeppelinBase {
constructor(string memory name_, string memory symbol_) ERC721("", "") {
_setNameAndSymbol(name_, symbol_);
}
}
abstract contract ERC721OpenZeppelinInitializable is OwnablePermissions, ERC721OpenZeppelinBase {
error ERC721OpenZeppelinInitializable__AlreadyInitializedERC721();
/// @notice Specifies whether or not the contract is initialized
bool private _erc721Initialized;
/// @dev Initializes parameters of ERC721 tokens.
/// These cannot be set in the constructor because this contract is optionally compatible with EIP-1167.
function initializeERC721(string memory name_, string memory symbol_) public {
_requireCallerIsContractOwner();
if(_erc721Initialized) {
revert ERC721OpenZeppelinInitializable__AlreadyInitializedERC721();
}
_erc721Initialized = true;
_setNameAndSymbol(name_, symbol_);
}
}This is a conventional OpenZeppelin ERC721 implementation.
CreatorTokenBase.sol
The following code configures the transfer security policy.
DEFAULT_TRANSFER_VALIDATOR
address public constant DEFAULT_TRANSFER_VALIDATOR = address(0x0000721C310194CcfC01E523fc93C9cCcFa2A0Ac);Overview Constant specifying the default transfer validator address.
Details Specifies the default address of the contract responsible for validating token transfers. The transfer validator manages security policies governing token transfers.
The default address in this version is 0x0000721C310194CcfC01E523fc93C9cCcFa2A0Ac.
DEFAULT_TRANSFER_SECURITY_LEVEL
TransferSecurityLevels public constant DEFAULT_TRANSFER_SECURITY_LEVEL = TransferSecurityLevels.One;Overview Constant specifying the default transfer security level.
Details Specifies the default security level of the token transfer policy. Security levels define restrictions on transfers.
Parameters
- None.
DEFAULT_OPERATOR_WHITELIST_ID
uint120 public constant DEFAULT_OPERATOR_WHITELIST_ID = uint120(1);Overview Constant specifying the default operator whitelist ID.
Details Specifies the default operator whitelist ID used by the token transfer security policy. The operator whitelist determines which addresses may operate on tokens under the configured policy.
transferValidator
ICreatorTokenTransferValidator private transferValidator;Overview Private variable holding the token transfer validator interface.
Details This variable is used to manage token transfer validation. The token contract interacts with the validator to determine whether transfers are permitted under the configured security policy.
setToDefaultSecurityPolicy
function setToDefaultSecurityPolicy() public virtual {
_requireCallerIsContractOwner();
setTransferValidator(DEFAULT_TRANSFER_VALIDATOR);
ICreatorTokenTransferValidator(DEFAULT_TRANSFER_VALIDATOR).setTransferSecurityLevelOfCollection(address(this), DEFAULT_TRANSFER_SECURITY_LEVEL);
ICreatorTokenTransferValidator(DEFAULT_TRANSFER_VALIDATOR).setOperatorWhitelistOfCollection(address(this), DEFAULT_OPERATOR_WHITELIST_ID);
}Overview Allows the contract owner to set the official transfer validator and its recommended default security policy.
Details
- Override this function to customize default behavior for an individual collection.
- Call
_requireCallerIsContractOwnerto verify that the caller is authorized as the contract owner. - Call
setTransferValidatorto configure the designated default validator. - Use
ICreatorTokenTransferValidatorto set the security level and operator whitelist to their default values.
setToCustomValidatorAndSecurityPolicy
function setToCustomValidatorAndSecurityPolicy(
address validator,
TransferSecurityLevels level,
uint120 operatorWhitelistId,
uint120 permittedContractReceiversAllowlistId) public {
_requireCallerIsContractOwner();
setTransferValidator(validator);
ICreatorTokenTransferValidator(validator).
setTransferSecurityLevelOfCollection(address(this), level);
ICreatorTokenTransferValidator(validator).
setOperatorWhitelistOfCollection(address(this), operatorWhitelistId);
ICreatorTokenTransferValidator(validator).
setPermittedContractReceiverAllowlistOfCollection(address(this), permittedContractReceiversAllowlistId);
}Overview Allows the contract owner to configure a custom transfer validator and security policy. Details
- Supply the custom validator address, transfer security level, operator whitelist ID, and permitted contract receiver list ID.
- Call
_requireCallerIsContractOwnerto verify that the caller is authorized as the contract owner. - Call
setTransferValidatorto configure the specified custom validator. - Use
ICreatorTokenTransferValidatorto set the security level, operator whitelist, and permitted contract receiver list to the specified values.
Parameters
validator- Custom validator contract address.
level- Transfer security level.
operatorWhitelistId- Operator whitelist ID.
permittedContractReceiversAllowlistId- Permitted contract receiver list ID.
setToCustomSecurityPolicy
function setToCustomSecurityPolicy(
TransferSecurityLevels level,
uint120 operatorWhitelistId,
uint120 permittedContractReceiversAllowlistId) public {
_requireCallerIsContractOwner();
ICreatorTokenTransferValidator validator = getTransferValidator();
if (address(validator) == address(0)) {
revert CreatorTokenBase__SetTransferValidatorFirst();
}
validator.setTransferSecurityLevelOfCollection(address(this), level);
validator.setOperatorWhitelistOfCollection(address(this), operatorWhitelistId);
validator.setPermittedContractReceiverAllowlistOfCollection(address(this), permittedContractReceiversAllowlistId);
}Overview Allows the contract owner to configure a custom security policy.
Details
- Call
_requireCallerIsContractOwnerto verify that the caller is authorized as the contract owner. - Call
getTransferValidatorto retrieve the transfer validator.- Revert if a transfer validator has not been configured.
- Use the retrieved validator to set the security level, operator whitelist, and permitted contract receiver list to the specified values.
- Revert if no transfer validator is configured.
Parameters
level- Transfer security level.
operatorWhitelistId- Operator whitelist ID.
permittedContractReceiversAllowlistId- Permitted contract receiver list ID.
setTransferValidator
function setTransferValidator(address transferValidator_) public {
_requireCallerIsContractOwner();
bool isValidTransferValidator = false;
if (transferValidator_.code.length > 0) {
try IERC165(transferValidator_).supportsInterface(type(ICreatorTokenTransferValidator).interfaceId)
returns (bool supportsInterface) {
isValidTransferValidator = supportsInterface;
} catch {}
}
if (transferValidator_ != address(0) && !isValidTransferValidator) {
revert CreatorTokenBase__InvalidTransferValidatorContract();
}
emit TransferValidatorUpdated(address(transferValidator), transferValidator_);
transferValidator = ICreatorTokenTransferValidator(transferValidator_);
}Overview Sets the token contract's transfer validator.
Details
- Call
_requireCallerIsContractOwnerto verify that the caller is authorized as the contract owner. - Check whether the supplied transfer validator contract is valid and revert if it is not.
- Update the transfer validator and emit
TransferValidatorUpdated. - Revert if the supplied validator is nonzero and does not support the
ICreatorTokenTransferValidatorinterface. - Revert if the caller is not authorized as the contract owner.
Parameters
transferValidator_- Transfer validator contract address.
getTransferValidator
function getTransferValidator() public view override returns (ICreatorTokenTransferValidator) {
return transferValidator;
}Overview Returns the address of this token contract's transfer validator.
Details
- This read-only function returns the token contract's configured validator address.
Return value
ICreatorTokenTransferValidator- Transfer validator contract interface.
getSecurityPolicy
function getSecurityPolicy() public view override returns (CollectionSecurityPolicy memory) {
if (address(transferValidator) != address(0)) {
return transferValidator.getCollectionSecurityPolicy(address(this));
}
return CollectionSecurityPolicy({
transferSecurityLevel: TransferSecurityLevels.Zero,
operatorWhitelistId: 0,
permittedContractReceiversId: 0
});
}Overview Returns this token contract's security policy.
Details
- If a transfer validator is configured, retrieve the security policy from it.
- Otherwise, return the default security policy.
- The policy includes the transfer security level, operator whitelist ID, and permitted contract receiver list ID.
Return value
CollectionSecurityPolicy- Struct representing the security policy.
getWhitelistedOperators
function getWhitelistedOperators() public view override returns (address[] memory) {
if (address(transferValidator) != address(0)) {
return transferValidator.getWhitelistedOperators(
transferValidator.getCollectionSecurityPolicy(address(this)).operatorWhitelistId);
}
return new address[](0);
}Overview Returns all operators on this token contract's operator whitelist.
Details
- If a transfer validator is configured, retrieve the operator whitelist ID from the validator and use it to retrieve the listed operators.
- If no validator is configured, return an empty address array.
- The call may be expensive and is best suited to off-chain read operations.
Return value
address[]- Array of whitelisted operator addresses.
getPermittedContractReceivers
function getPermittedContractReceivers() public view override returns (address[] memory) {
if (address(transferValidator) != address(0)) {
return transferValidator.getPermittedContractReceivers(
transferValidator.getCollectionSecurityPolicy(address(this)).permittedContractReceiversId);
}
return new address[](0);
}Overview Returns the list of permitted contract receivers for this token contract.
Details
- If a transfer validator is configured, retrieve the permitted contract receiver list ID and use it to retrieve the permitted addresses.
- If no validator is configured, return an empty address array.
- The call may be expensive and is best suited to off-chain read operations.
Return value
address[]- Array of permitted contract receiver addresses.
isOperatorWhitelisted
function isOperatorWhitelisted(address operator) public view override returns (bool) {
if (address(transferValidator) != address(0)) {
return transferValidator.isOperatorWhitelisted(
transferValidator.getCollectionSecurityPolicy(address(this)).operatorWhitelistId, operator);
}
return false;
}Overview Checks whether an operator is whitelisted for this token contract.
Details
- If a transfer validator is configured, retrieve the operator whitelist ID and check whether the specified operator is on that list.
- If no transfer validator is configured, return
false.
Parameters
operator- Operator address to check.
Return value
booltrueif the operator is whitelisted; otherwise,false.
isContractReceiverPermitted
function isContractReceiverPermitted(address receiver) public view override returns (bool) {
if (address(transferValidator) != address(0)) {
return transferValidator.isContractReceiverPermitted(
transferValidator.getCollectionSecurityPolicy(address(this)).permittedContractReceiversId, receiver);
}
return false;
}Overview Checks whether a contract receiver is permitted for this token contract.
Details
- If a transfer validator is configured, retrieve the permitted contract receiver list ID and check whether the specified receiver is on the list.
- If no transfer validator is configured, return
false.
Parameters
receiver- Receiver address to check.
Return value
booltrueif the contract receiver is permitted; otherwise,false.
isTransferAllowed
function isTransferAllowed(address caller, address from, address to) public view override returns (bool) {
if (address(transferValidator) != address(0)) {
try transferValidator.applyCollectionTransferPolicy(caller, from, to) {
return true;
} catch {
return false;
}
}
return true;
}Overview Determines whether a transfer is allowed under the token contract's security policy.
Details
- If a transfer validator is configured, use it to check whether the transfer is permitted.
- If the validation call reverts, treat the transfer as disallowed.
- If no transfer validator is configured, treat the transfer as allowed by this validation layer.
- Use this function to simulate whether the specified
callermay transfer tokens fromfromtotounder the token's security policy.
Parameters
caller- Simulated caller address.
from- Sender address.
to- Receiver address.
Return value
booltrueif the transfer is allowed by the policy; otherwise,false.
_preValidateTransfer
function _preValidateTransfer(
address caller,
address from,
address to,
uint256 /*tokenId*/,
uint256 /*value*/) internal virtual override {
if (address(transferValidator) != address(0)) {
transferValidator.applyCollectionTransferPolicy(caller, from, to);
}
}Overview Validates a token transfer before execution and checks that it is permitted under the token contract's security policy.
Details
- If a transfer validator is configured, use it to validate the transfer.
- Revert if the transfer is not permitted.
- If no validator is configured, skip this validation and allow the transfer at this layer.
- The derived contract is responsible for overriding
_beforeTokenTransferor its equivalent and calling_validateBeforeTransfer.
Parameters
caller- Caller address.
from- Sender address.
to- Receiver address.
CreatorTokenTransferValidator
Next, examine the CreatorTokenTransferValidator contract, which provides the core ERC721C transfer validation functionality.
DEFAULT_ACCESS_CONTROL_ADMIN_ROLE
bytes32 private constant DEFAULT_ACCESS_CONTROL_ADMIN_ROLE = 0x00;Overview Byte value representing the default access-control administrator role.
Details Identifies the administrative role used for access control. It is used to check authorization for access-control-related operations.
DEFAULT_TRANSFER_SECURITY_LEVEL
TransferSecurityLevels public constant DEFAULT_TRANSFER_SECURITY_LEVEL = TransferSecurityLevels.Zero;Overview Enum value representing the default token transfer security level.
Details Used to select the security policy governing token transfer operations. The default security level is Zero. Individual collections can configure other supported levels.
lastOperatorWhitelistId
uint120 private lastOperatorWhitelistId;Overview Variable storing the last allocated operator whitelist ID.
Details Used to assign unique IDs to operator whitelists. Its value increases whenever a new operator whitelist is created.
lastPermittedContractReceiverAllowlistId
uint120 private lastPermittedContractReceiverAllowlistId;Overview Variable storing the last allocated permitted contract receiver list ID.
Details Used to assign unique IDs to permitted contract receiver lists. Its value increases whenever a new receiver list is created.
transferSecurityPolicies
mapping (TransferSecurityLevels => TransferSecurityPolicy) public transferSecurityPolicies;Overview
Mapping associating token transfer security policies with TransferSecurityLevels.
Details
Stores the transfer security policy for each level.
Each policy is associated with a value of the TransferSecurityLevels enum.
collectionSecurityPolicies
mapping (address => CollectionSecurityPolicy) private collectionSecurityPolicies;Overview Mapping associating each collection address with its security policy.
Details Stores each token collection's security policy. Used to retrieve the security policy associated with a collection address.
operatorWhitelistOwners
mapping (uint120 => address) public operatorWhitelistOwners;Overview Mapping associating operator whitelist IDs with their owners.
Details Stores the owner address for each operator whitelist ID. Used to identify the owner of an operator whitelist.
permittedContractReceiverAllowlistOwners
mapping (uint120 => address) public permittedContractReceiverAllowlistOwners;Overview Mapping associating permitted contract receiver list IDs with their owners.
Details Stores the owner address for each permitted contract receiver list ID. Used to identify the list owner.
operatorWhitelists
mapping (uint120 => EnumerableSet.AddressSet) private operatorWhitelists;Overview Mapping associating operator whitelists with their IDs.
Details
Stores the operator whitelist for each ID.
Each whitelist is implemented as an EnumerableSet.AddressSet containing permitted operator addresses.
permittedContractReceiverAllowlists
mapping (uint120 => EnumerableSet.AddressSet) private permittedContractReceiverAllowlists;Overview Mapping associating permitted contract receiver lists with their IDs.
Details
Stores the permitted contract receiver list for each ID.
Each list is implemented as an EnumerableSet.AddressSet containing permitted contract receiver addresses.
constructor
constructor(address defaultOwner) EOARegistry() {
transferSecurityPolicies[TransferSecurityLevels.Zero] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.None,
receiverConstraints: ReceiverConstraints.None
});
transferSecurityPolicies[TransferSecurityLevels.One] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.OperatorWhitelistEnableOTC,
receiverConstraints: ReceiverConstraints.None
});
transferSecurityPolicies[TransferSecurityLevels.Two] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.OperatorWhitelistDisableOTC,
receiverConstraints: ReceiverConstraints.None
});
transferSecurityPolicies[TransferSecurityLevels.Three] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.OperatorWhitelistEnableOTC,
receiverConstraints: ReceiverConstraints.NoCode
});
transferSecurityPolicies[TransferSecurityLevels.Four] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.OperatorWhitelistEnableOTC,
receiverConstraints: ReceiverConstraints.EOA
});
transferSecurityPolicies[TransferSecurityLevels.Five] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.OperatorWhitelistDisableOTC,
receiverConstraints: ReceiverConstraints.NoCode
});
transferSecurityPolicies[TransferSecurityLevels.Six] = TransferSecurityPolicy({
callerConstraints: CallerConstraints.OperatorWhitelistDisableOTC,
receiverConstraints: ReceiverConstraints.EOA
});
uint120 id = ++lastOperatorWhitelistId;
operatorWhitelistOwners[id] = defaultOwner;
emit CreatedAllowlist(AllowlistTypes.Operators, id, "DEFAULT OPERATOR WHITELIST");
emit ReassignedAllowlistOwnership(AllowlistTypes.Operators, id, defaultOwner);
}Overview Initializes the contract using the supplied default owner address.
Details Initializes token transfer security policies and the operator whitelist. Sets the default owner, configures the policies, and emits the initial events.
Parameters
defaultOwner- Default owner address.
applyCollectionTransferPolicy
function applyCollectionTransferPolicy(address caller, address from, address to) external view override {
address collection = _msgSender();
CollectionSecurityPolicy memory collectionSecurityPolicy = collectionSecurityPolicies[collection];
TransferSecurityPolicy memory transferSecurityPolicy =
transferSecurityPolicies[collectionSecurityPolicy.transferSecurityLevel];
if (transferSecurityPolicy.receiverConstraints == ReceiverConstraints.NoCode) {
if (to.code.length > 0) {
if (!isContractReceiverPermitted(collectionSecurityPolicy.permittedContractReceiversId, to)) {
revert CreatorTokenTransferValidator__ReceiverMustNotHaveDeployedCode();
}
}
} else if (transferSecurityPolicy.receiverConstraints == ReceiverConstraints.EOA) {
if (!isVerifiedEOA(to)) {
if (!isContractReceiverPermitted(collectionSecurityPolicy.permittedContractReceiversId, to)) {
revert CreatorTokenTransferValidator__ReceiverProofOfEOASignatureUnverified();
}
}
}
if (transferSecurityPolicy.callerConstraints != CallerConstraints.None) {
if(operatorWhitelists[collectionSecurityPolicy.operatorWhitelistId].length() > 0) {
if (!isOperatorWhitelisted(collectionSecurityPolicy.operatorWhitelistId, caller)) {
if (transferSecurityPolicy.callerConstraints == CallerConstraints.OperatorWhitelistEnableOTC) {
if (caller != from) {
revert CreatorTokenTransferValidator__CallerMustBeWhitelistedOperator();
}
} else {
revert CreatorTokenTransferValidator__CallerMustBeWhitelistedOperator();
}
}
}
}
}Overview Applies the token transfer policy of a collection.
Details
Applies the security policy to a token transfer in the specified collection.
Whether the transfer is allowed or rejected depends on the configured policy.
Checks whether the applicable CallerConstraints and ReceiverConstraints are satisfied and reverts if they are not.
Parameters
caller- Address initiating the token transfer.
from- Token source address.
to- Token destination address.
createOperatorWhitelist
function createOperatorWhitelist(string calldata name) external override returns (uint120) {
uint120 id = ++lastOperatorWhitelistId;
operatorWhitelistOwners[id] = _msgSender();
emit CreatedAllowlist(AllowlistTypes.Operators, id, name);
emit ReassignedAllowlistOwnership(AllowlistTypes.Operators, id, _msgSender());
return id;
}Overview Creates a new operator whitelist.
Details Creates a new operator whitelist with the specified name. Ownership of the new whitelist is assigned to the caller. The list is created, its owner is assigned, and the corresponding events are emitted.
Parameters
name- Name of the new operator whitelist.
Return value
id- ID of the new operator whitelist.
createPermittedContractReceiverAllowlist
function createPermittedContractReceiverAllowlist(string calldata name) external override returns (uint120) {
uint120 id = ++lastPermittedContractReceiverAllowlistId;
permittedContractReceiverAllowlistOwners[id] = _msgSender();
emit CreatedAllowlist(AllowlistTypes.PermittedContractReceivers, id, name);
emit ReassignedAllowlistOwnership(AllowlistTypes.PermittedContractReceivers, id, _msgSender());
return id;
}Overview Creates a new permitted contract receiver list.
Details Creates a new permitted contract receiver list with the specified name. Ownership of the new whitelist is assigned to the caller. The list is created, its owner is assigned, and the corresponding events are emitted.
Parameters
name- Name of the new permitted contract receiver list.
Return value
id- ID of the new permitted contract receiver list.
reassignOwnershipOfOperatorWhitelist
function reassignOwnershipOfOperatorWhitelist(uint120 id, address newOwner) external override {
if(newOwner == address(0)) {
revert CreatorTokenTransferValidator__AllowlistOwnershipCannotBeTransferredToZeroAddress();
}
_reassignOwnershipOfOperatorWhitelist(id, newOwner);
}Overview Transfers ownership of an operator whitelist to a new owner.
Details Transfers ownership of the specified operator whitelist to the new owner. Reverts if the new owner is the zero address or the caller is not the current whitelist owner. On success, transfers ownership and emits the corresponding event.
Parameters
id- Operator whitelist ID.
newOwner- New owner address.
reassignOwnershipOfPermittedContractReceiverAllowlist
function reassignOwnershipOfPermittedContractReceiverAllowlist(uint120 id, address newOwner) external override {
if(newOwner == address(0)) {
revert CreatorTokenTransferValidator__AllowlistOwnershipCannotBeTransferredToZeroAddress();
}
_reassignOwnershipOfPermittedContractReceiverAllowlist(id, newOwner);
}Overview Transfers ownership of a permitted contract receiver list to a new owner.
Details Transfers ownership of the specified permitted contract receiver list to the new owner. Reverts if the new owner is the zero address or the caller is not the current receiver list owner. On success, transfers ownership and emits the corresponding event.
Parameters
id- Permitted contract receiver list ID.
newOwner- New owner address.
renounceOwnershipOfOperatorWhitelist
function renounceOwnershipOfOperatorWhitelist(uint120 id) external override {
_reassignOwnershipOfOperatorWhitelist(id, address(0));
}Overview Renounces ownership of an operator whitelist, preventing further modifications to the list.
Details Renounces ownership of the specified operator whitelist so that its contents can no longer be modified. Reverts if the caller is not the owner of the specified operator whitelist. On success, renounces ownership and emits the corresponding event.
Parameters
id- Operator whitelist ID.
renounceOwnershipOfPermittedContractReceiverAllowlist
function renounceOwnershipOfPermittedContractReceiverAllowlist(uint120 id) external override {
_reassignOwnershipOfPermittedContractReceiverAllowlist(id, address(0));
}Overview Renounces ownership of a permitted contract receiver list, preventing further modifications to the list.
Details Renounces ownership of the specified permitted contract receiver list so that its contents can no longer be modified. Reverts if the caller is not the owner of the specified permitted contract receiver list. On success, renounces ownership and emits the corresponding event.
Parameters
id- Permitted contract receiver list ID.
setTransferSecurityLevelOfCollection
function setTransferSecurityLevelOfCollection(
address collection,
TransferSecurityLevels level) external override {
_requireCallerIsNFTOrContractOwnerOrAdmin(collection);
collectionSecurityPolicies[collection].transferSecurityLevel = level;
emit SetTransferSecurityLevel(collection, level);
}Overview Sets the transfer security level for a collection.
Details Updates the specified collection's transfer security level. Reverts if the caller is neither the collection contract itself nor its authorized owner or administrator. On success, updates the configuration and emits the corresponding event.
Parameters
collection- Collection address.
level- New transfer security level to apply.
setOperatorWhitelistOfCollection
function setOperatorWhitelistOfCollection(address collection, uint120 id) external override {
_requireCallerIsNFTOrContractOwnerOrAdmin(collection);
if (id > lastOperatorWhitelistId) {
revert CreatorTokenTransferValidator__AllowlistDoesNotExist();
}
collectionSecurityPolicies[collection].operatorWhitelistId = id;
emit SetAllowlist(AllowlistTypes.Operators, collection, id);
}Overview Sets the operator whitelist for a collection.
Details Updates the operator whitelist assigned to the specified collection. Reverts if the caller is neither the collection contract itself nor its authorized owner or administrator. Also reverts if the specified operator whitelist ID does not exist. On success, updates the configuration and emits the corresponding event.
Parameters
collection- Collection address.
id- Operator whitelist ID.
setPermittedContractReceiverAllowlistOfCollection
function setPermittedContractReceiverAllowlistOfCollection(address collection, uint120 id) external override {
_requireCallerIsNFTOrContractOwnerOrAdmin(collection);
if (id > lastPermittedContractReceiverAllowlistId) {
revert CreatorTokenTransferValidator__AllowlistDoesNotExist();
}
collectionSecurityPolicies[collection].permittedContractReceiversId = id;
emit SetAllowlist(AllowlistTypes.PermittedContractReceivers, collection, id);
}Overview Sets the permitted contract receiver list for a collection.
Details Updates the permitted contract receiver list assigned to the specified collection. Reverts if the caller is neither the collection contract itself nor its authorized owner or administrator. Also reverts if the specified permitted contract receiver list ID does not exist. On success, updates the configuration and emits the corresponding event.
Parameters
collection- Collection address.
id- Permitted contract receiver list ID.
addOperatorToWhitelist
function addOperatorToWhitelist(uint120 id, address operator) external override {
_requireCallerOwnsOperatorWhitelist(id);
if (!operatorWhitelists[id].add(operator)) {
revert CreatorTokenTransferValidator__AddressAlreadyAllowed();
}
emit AddedToAllowlist(AllowlistTypes.Operators, id, operator);
}Overview Adds an operator to an operator whitelist.
Details Adds the specified operator to the specified whitelist. Reverts if the caller does not own the list or the operator is already included. On success, adds the operator and emits the corresponding event.
Parameters
id- Operator whitelist ID.
operator- Operator address to add.
addPermittedContractReceiverToAllowlist
function addPermittedContractReceiverToAllowlist(uint120 id, address receiver) external override {
_requireCallerOwnsPermittedContractReceiverAllowlist(id);
if (!permittedContractReceiverAllowlists[id].add(receiver)) {
revert CreatorTokenTransferValidator__AddressAlreadyAllowed();
}
emit AddedToAllowlist(AllowlistTypes.PermittedContractReceivers, id, receiver);
}Overview Adds a contract address to a permitted contract receiver list.
Details Adds the specified contract address to the specified permitted receiver list. Reverts if the caller does not own the list or the contract address is already included. On success, adds the contract address and emits the corresponding event.
Parameters
id- Permitted contract receiver list ID.
receiver- Contract address to add.
removeOperatorFromWhitelist
function removeOperatorFromWhitelist(uint120 id, address operator) external override {
_requireCallerOwnsOperatorWhitelist(id);
if (!operatorWhitelists[id].remove(operator)) {
revert CreatorTokenTransferValidator__AddressNotAllowed();
}
emit RemovedFromAllowlist(AllowlistTypes.Operators, id, operator);
}Overview Removes an operator from an operator whitelist.
Details Removes the specified operator from the specified whitelist. Reverts if the caller does not own the list or the operator is not included. On success, removes the operator and emits the corresponding event.
Parameters
id- Operator whitelist ID.
operator- Operator address to remove.
removePermittedContractReceiverFromAllowlist
function removePermittedContractReceiverFromAllowlist(uint120 id, address receiver) external override {
_requireCallerOwnsPermittedContractReceiverAllowlist(id);
if (!permittedContractReceiverAllowlists[id].remove(receiver)) {
revert CreatorTokenTransferValidator__AddressNotAllowed();
}
emit RemovedFromAllowlist(AllowlistTypes.PermittedContractReceivers, id, receiver);
}Overview Removes a contract address from a permitted contract receiver list.
Details Removes the specified contract address from the specified receiver list. Reverts if the caller does not own the list or the contract address is not included. On success, removes the contract address and emits the corresponding event.
Parameters
id- Permitted contract receiver list ID.
receiver- Contract address to remove.
getCollectionSecurityPolicy
function getCollectionSecurityPolicy(address collection)
external view override returns (CollectionSecurityPolicy memory) {
return collectionSecurityPolicies[collection];
}Overview Retrieves the security policy for a specified collection.
Details Retrieves the specified collection's security policy. The policy includes the transfer security level, operator whitelist ID, and permitted contract receiver list ID.
Parameters
collection- Collection address.
Return value
CollectionSecurityPolicy- Struct containing the collection's security policy.
getWhitelistedOperators
function getWhitelistedOperators(uint120 id) external view override returns (address[] memory) {
return operatorWhitelists[id].values();
}Overview Retrieves the operators included in an operator whitelist.
Details Retrieves the addresses of operators included in the specified whitelist.
Parameters
id- Operator whitelist ID.
Return value
address[]- Array of whitelisted operator addresses.
getPermittedContractReceivers
function getPermittedContractReceivers(uint120 id) external view override returns (address[] memory) {
return permittedContractReceiverAllowlists[id].values();
}Overview Retrieves the permitted contract receiver addresses in a specified list.
Details Retrieves all permitted contract receiver addresses in the specified list.
Parameters
id- Permitted contract receiver list ID.
Return value
address[]- Array of permitted contract receiver addresses in the list.
isOperatorWhitelisted
function isOperatorWhitelisted(uint120 id, address operator) public view override returns (bool) {
return operatorWhitelists[id].contains(operator);
}Overview Checks whether an operator belongs to a specified operator whitelist.
Details
Returns true if the specified operator is included in the list and false otherwise.
Parameters
id- Operator whitelist ID.
operator- Operator address to check.
Return value
booltrueif the operator is included in the specified whitelist; otherwise,false.
isContractReceiverPermitted
function isContractReceiverPermitted(uint120 id, address receiver) public view override returns (bool) {
return permittedContractReceiverAllowlists[id].contains(receiver);
}Overview Checks whether a contract address belongs to a specified permitted contract receiver list.
Details
Checks whether the specified contract address is included in the specified receiver list.
Returns true if it is included and false otherwise.
Parameters
id- Permitted contract receiver list ID.
receiver- Contract address to check.
Return value
booltrueif the contract address is included in the specified permitted contract receiver list; otherwise,false.
supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override(EOARegistry, IERC165) returns (bool) {
return
interfaceId == type(ITransferValidator).interfaceId ||
interfaceId == type(ITransferSecurityRegistry).interfaceId ||
interfaceId == type(ICreatorTokenTransferValidator).interfaceId ||
super.supportsInterface(interfaceId);
}Overview Checks whether a specified interface is supported.
Details
Determines whether the contract supports the specified interface.
Returns true for a supported interface and false otherwise.
Supports ERC165 interface detection, including interfaces associated with transfer validation.
Parameters
interfaceId- Interface ID to check.
Return value
booltrueif the specified interface is supported; otherwise,false.
_requireCallerIsNFTOrContractOwnerOrAdmin
function _requireCallerIsNFTOrContractOwnerOrAdmin(address tokenAddress) internal view {
bool callerHasPermissions = false;
if(tokenAddress.code.length > 0) {
callerHasPermissions = _msgSender() == tokenAddress;
if(!callerHasPermissions) {
try IOwnable(tokenAddress).owner() returns (address contractOwner) {
callerHasPermissions = _msgSender() == contractOwner;
} catch {}
if(!callerHasPermissions) {
try IAccessControl(tokenAddress).hasRole(DEFAULT_ACCESS_CONTROL_ADMIN_ROLE, _msgSender())
returns (bool callerIsContractAdmin) {
callerHasPermissions = callerIsContractAdmin;
} catch {}
}
}
}
if(!callerHasPermissions) {
revert CreatorTokenTransferValidator__CallerMustHaveElevatedPermissionsForSpecifiedNFT();
}
}Overview Checks that the caller is the specified NFT contract or an authorized owner or administrator of that contract.
Details Verifies whether the caller satisfies the ownership or administration requirements for the specified NFT contract. Reverts if the caller lacks the required authority.
Parameters
tokenAddress- NFT contract address to check.
_reassignOwnershipOfOperatorWhitelist
function _reassignOwnershipOfOperatorWhitelist(uint120 id, address newOwner) private {
_requireCallerOwnsOperatorWhitelist(id);
operatorWhitelistOwners[id] = newOwner;
emit ReassignedAllowlistOwnership(AllowlistTypes.Operators, id, newOwner);
}Overview Transfers ownership of an operator whitelist to another owner.
Details Updates the owner of the specified operator whitelist to the new address. Reverts if the caller is not the current operator whitelist owner. On success, transfers ownership and emits the corresponding event.
Parameters
id- Operator whitelist ID.
newOwner- New owner address.
_reassignOwnershipOfPermittedContractReceiverAllowlist
function _reassignOwnershipOfPermittedContractReceiverAllowlist(uint120 id, address newOwner) private {
_requireCallerOwnsPermittedContractReceiverAllowlist(id);
permittedContractReceiverAllowlistOwners[id] = newOwner;
emit ReassignedAllowlistOwnership(AllowlistTypes.PermittedContractReceivers, id, newOwner);
}Overview Transfers ownership of a permitted contract receiver list to another owner.
Details Updates the owner of the specified permitted contract receiver list to the new address. Reverts if the caller is not the current permitted contract receiver list owner. On success, transfers ownership and emits the corresponding event.
Parameters
id- Permitted contract receiver list ID.
newOwner- New owner address.
_requireCallerOwnsOperatorWhitelist
function _requireCallerOwnsOperatorWhitelist(uint120 id) private view {
if (_msgSender() != operatorWhitelistOwners[id]) {
revert CreatorTokenTransferValidator__CallerDoesNotOwnAllowlist();
}
}Overview Checks that the caller owns a specified operator whitelist.
Details Verifies whether the caller is the owner of the specified operator whitelist. Reverts if the caller is not the owner.
Parameters
id- Operator whitelist ID.
_requireCallerOwnsPermittedContractReceiverAllowlist
function _requireCallerOwnsPermittedContractReceiverAllowlist(uint120 id) private view {
if (_msgSender() != permittedContractReceiverAllowlistOwners[id]) {
revert CreatorTokenTransferValidator__CallerDoesNotOwnAllowlist();
}
}Overview Checks that the caller owns a specified permitted contract receiver list.
Details Verifies whether the caller is the owner of the specified permitted contract receiver list. Reverts if the caller is not the owner.
Parameters
id- Permitted contract receiver list ID.
References
Conclusion
This article covered ERC721C, a mechanism for enforcing transfer policies designed to protect on-chain royalties. I hope it helped clarify the mechanism.
If you have questions, feel free to reach out via Twitter DM.
I also publish articles on the following platforms.




