question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactoring function ownerOf in ERC721.sol

See original GitHub issue

Check the presence of a token using the function _exists. Now the ownerOf function corresponds to the getApproved function.

function ownerOf(uint256 tokenId) public view returns (address) {
        require(_exists(tokenId));
        return _tokenOwner[tokenId];
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nventurocommented, Apr 3, 2019

Ahh, I see. For reference for everyone else, these are the functions being discussed:

function ownerOf(uint256 tokenId) public view returns (address) {
    address owner = _tokenOwner[tokenId];
    require(owner != address(0));
    return owner;
}

function _exists(uint256 tokenId) internal view returns (bool) {
    address owner = _tokenOwner[tokenId];
    return owner != address(0);
}

Yes, I did think of that when revising ownerOf recently, but unfortunately due to how Solidity’s codegen works, that would mean performing an extra SLOAD (since _exists doesn’t return the owner). I think ownerOf is short and readable enough that the benefit of performing that deduplication may not be warranted. @frangio thoughts on this?

0reactions
frangiocommented, Apr 3, 2019

I agree with @nventuro that the code is short enough that we should prioritize the cheaper implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can ChatGPT really be trusted to write a smart contract or to ...
Developers are beginning to explore the potential of asking ChatGPT to assist with writing, reviewing or refactoring code, as well as providing ...
Read more >
How to send ether to erc721 token owner? - Stack Overflow
ownerOf returns address, so I set payable address inside of sendEther function. However, error says 'Type address is not implicitly convertible ...
Read more >
ERC721.sol - aaron bloomfield @ github.io
function ownerOf (uint256 tokenId) public view virtual override returns (address) { address owner = _ownerOf(tokenId); require(owner != address(0), "ERC721: ...
Read more >
Address 0x6261d8e873b9a7be666d0aa07357bc9d6bcc7feb
File 1 of 14 : Marketplace.sol ... File 2 of 14 : ERC721.sol ... function ownerOf(uint256 tokenId) public view virtual override returns ......
Read more >
Ethereum Contract Diff Checker - Etherscan
_ */ function functionCall(address target, bytes memory data) internal returns ... Strings.sol"; /** * @title ERC721 Non-Fungible Token Standard basic ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found