5

I saw the contract as getApproved and ownerOf functions. What is the difference between owning the token under ERC721 and having approval? When the tokenid is transferred does that transfer ownership or approval?

/**
 * @dev Gets the approved address for a token ID, or zero if no address set
 * Reverts if the token ID does not exist.
 * @param tokenId uint256 ID of the token to query the approval of
 * @return address currently approved for the given token ID
 */
function getApproved(uint256 tokenId) public view returns (address) {
    require(_exists(tokenId));
    return _tokenApprovals[tokenId];
}

/**
 * @dev Gets the owner of the specified token ID
 * @param tokenId uint256 ID of the token to query the owner of
 * @return address currently marked as the owner of the given token ID
 */
function ownerOf(uint256 tokenId) public view returns (address) {
    address owner = _tokenOwner[tokenId];
    require(owner != address(0));
    return owner;
}
Trevor Lee Oakley
  • 2,327
  • 2
  • 19
  • 48

1 Answers1

3

I think the answer is that an approved account can transfer on behalf of the owner.

/**
 * @dev Sets or unsets the approval of a given operator
 * An operator is allowed to transfer all tokens of the sender on their behalf
 * @param to operator address to set the approval
 * @param approved representing the status of the approval to be set
 */
function setApprovalForAll(address to, bool approved) public {
    require(to != msg.sender);
    _operatorApprovals[msg.sender][to] = approved;
    emit ApprovalForAll(msg.sender, to, approved);
}
Trevor Lee Oakley
  • 2,327
  • 2
  • 19
  • 48
  • 2
    And for the other half of the question. Yes, when transferred, the approved address is reset. Reference: the transfer function in https://eips.ethereum.org/EIPS/eip-721#specification – William Entriken Feb 14 '19 at 16:13