Just like with the ERC-20 chapter, in this section we will examine each of the functions that make up the ERC-721 interface. Below is the ERC-721 interface seen from the last section:
_balanceOf(address owner)
Similar to the function of the same name in the ERC20 interface, balanceOf returns the number of non-fungible tokens that _owner has.
_ownerOf(uint256 tokenId)
This function returns the address that owns the non-fungible token with id _tokenId
__safeTransferFrom(address _from, address to, uint256 tokenId, bytes data)
This function is very similar to the transferFrom function in the ERC-20 specification. safeTransferFrom transfer a NFT of id _tokenId from _from to _to . However, after transferring the token, safeTransferFrom checks if the account is capable of handling the NFT (via passing in the arguments _from, _to, _tokenId, and data. If _to is not capable of handling the NFT, safeTransferFrom reverts.
__safeTransferFrom(address _from, address to, uint256 tokenId)
This function behaves exactly like the function above, except that the argument data is set to the empty string.
__transferFrom(address _from, address to, uint256 tokenId)
This function behaves exactly like safeTransferFrom, except that we do not check if _to is capable of receiving the NFT with id _tokenId.
__approve(address approved, uint256 tokenId)
When called, this function gives _approved transfer rights to the NFT with id _tokenId. This function fails if an account without transfer rights to the NFT is the caller.
__setApprovalForAll(address operator, bool approved)
When called, this function gives _operator either transfer rights to all NFTs of the function caller (if _approved is true) or revokes transfer rights to all NFTs of the function caller (if _approved is false).
_getApproved(uint256 tokenId)
This function returns the address of the account with transfer rights to the NFT with id _tokenId.
__isApprovedForAll(address owner, address operator)
This function returns true if _operator has transfer rights to all of the NFTs that _owner holds, and false otherwise.