I have restrict the setApprovalForAll function : // Modified setApprovalForAll function…
- User
I have restrict the setApprovalForAll function : // Modified setApprovalForAll function function setApprovalForAll(address operator, bool approved) public virtual override(ERC721A, IERC721A) onlyWhitelistedOrOwner { require(operator != msg.sender, "Approve to caller");
_operatorApprovals[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); }How to restrict this now in the same way: function approve(address to, uint256 tokenId) public virtual override { address owner = ownerOf(tokenId);
if (_msgSenderERC721A() != owner) if (!isApprovedForAll(owner, _msgSenderERC721A())) { revert ApprovalCallerNotOwnerNorApproved(); } _tokenApprovals[tokenId].value = to; emit Approval(owner, to, tokenId); } - Assistant
To modify the
approvefunction for ERC721A to restrict it in the same way as yoursetApprovalForAllfunction (i.e., to only allow whitelisted users or the owner of the token to approve another address), you can introduce a modifier similar toonlyWhitelistedOrOwner. This modifier would check if the caller is either whitelisted or the owner of the token. - User
I have restrict the setApprovalForAll function : mapping(address => bool) private _whitelisted; mapping(address => mapping(address => bool)) private _operatorApprovals;
// Modified setApprovalForAll function function setApprovalForAll(address operator, bool approved) public virtual override(ERC721A, IERC721A) onlyWhitelistedOrOwner { require(operator != msg.sender, "Approve to caller"); _operatorApprovals[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); } // Function to whitelist an address function whitelistAddress(address account) external onlyOwner { _whitelisted[account] = true; emit Whitelisted(account, true); } // Function to remove address from whitelist function removeWhitelistedAddress(address account) external onlyOwner { _whitelisted[account] = false; emit Whitelisted(account, false); }How to restrict the following function in the same way while using the same logic: function approve(address to, uint256 tokenId) public virtual override { address owner = ownerOf(tokenId);
if (_msgSenderERC721A() != owner) if (!isApprovedForAll(owner, _msgSenderERC721A())) { revert ApprovalCallerNotOwnerNorApproved(); } _tokenApprovals[tokenId].value = to; emit Approval(owner, to, tokenId); } - Assistant