Basic implementations (ERC721 and ERC1155) of a Mint Permissions contract that works with a singular creator contract are shown below. Note the approveMint function requires the sender to be the configured creator.
ERC721
abstractcontractERC721CreatorMintPermissionsisERC165, AdminControl, IERC721CreatorMintPermissions {addressinternalimmutable _creator;constructor(address creator_) {require(ERC165Checker.supportsInterface(creator_, type(IERC721CreatorCore).interfaceId),"Must implement IERC721CreatorCore"); _creator = creator_; }/** * @dev See {IERC165-supportsInterface}. */functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverride(ERC165,IERC165,AdminControl) returns (bool) {return interfaceId == type(IERC721CreatorMintPermissions).interfaceId|| super.supportsInterface(interfaceId); }/** * @dev See {IERC721CreatorMintPermissions-approve}. */functionapproveMint(address,address,uint256) publicvirtualoverride {require(msg.sender == _creator,"Can only be called by token creator"); }}
ERC155
abstractcontractERC1155CreatorMintPermissionsisERC165, AdminControl, IERC1155CreatorMintPermissions {addressinternalimmutable _creator;constructor(address creator_) {require(ERC165Checker.supportsInterface(creator_, type(IERC1155CreatorCore).interfaceId),"Must implement IERC1155CreatorCore"); _creator = creator_; }/** * @dev See {IERC165-supportsInterface}. */functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverride(ERC165,IERC165,AdminControl) returns (bool) {return interfaceId == type(IERC1155CreatorMintPermissions).interfaceId|| super.supportsInterface(interfaceId); }/** * @dev See {IERC1155CreatorMintPermissions-approve}. */functionapproveMint(address,address[] calldata,uint256[] calldata,uint256[] calldata) publicvirtualoverride {require(msg.sender == _creator,"Can only be called by token creator"); }}
Adding a Mint Permissions Contract
Adding a Mint Permissions contract is similar to registering an extension. Add a mint permissions contract by calling the setMintPermissions function and indicating the registered extension contract and mint permissions contract you wish to set.