Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

The getApproved function

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content