August 2019
Intermediate to advanced
486 pages
13h 52m
English
The getApproved() function returns the address that has the approval for the given tokenId. As you can see, the function takes tokenId as a function argument for which you want to know the address of the approved account:
function getApproved(uint256 tokenId) public view returns (address) { require(_exists(tokenId)); return _tokenApprovals[tokenId];}
As you can see in the preceding code that the function calls an internal _exists() function to ensure that the given tokenId of an NFT exists, and that it has been assigned to a non address(0) owner, otherwise, the function call fails. After this check, it fetches and returns the token owner's address.