diff --git a/contracts/token/ERC721/ERC721.sol b/contracts/token/ERC721/ERC721.sol index 428338d900c..1236936a408 100644 --- a/contracts/token/ERC721/ERC721.sol +++ b/contracts/token/ERC721/ERC721.sol @@ -111,8 +111,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); - require(to != owner, "ERC721: approval to current owner"); - + require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not token owner or approved for all" @@ -183,7 +182,8 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. - * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. + * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, + * which is called upon a safe transfer. * * Emits a {Transfer} event. */ @@ -229,7 +229,8 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * Requirements: * * - `tokenId` must not exist. - * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. + * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, + * which is called upon a safe transfer. * * Emits a {Transfer} event. */ @@ -364,8 +365,10 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { + address owner = ERC721.ownerOf(tokenId); + require(to != owner, "ERC721: approval to current owner"); _tokenApprovals[tokenId] = to; - emit Approval(ERC721.ownerOf(tokenId), to, tokenId); + emit Approval(owner, to, tokenId); } /**