I am building a smart contract that checks the ownership of NFTs in a very simple function call:
function ownershipCheck(uint deployedID) public view returns (address) {
address holder = deployedNFT.ownerOf(deployedID);
if(_msgSender() != holder){revert InsufficientFunds();}
}
According to hardhat, this line
address holder = deployedNFT.ownerOf(deployedID);
is the source of the revert. I manually checked the ownership by calling the contract directly with the tokenID i am trying to check with my ownershipCheck() function and it returns the address of the expected owner. so the ERC721 contract should work correctly in terms of checking ownership (I am using the latest openzeppelin contracts).
this is the function on the interface:
interface IERC721 {
function ownerOf(uint256 tokenId) external view returns (address owner);
}
Any idea why this might be reverting?
From the ERC-721 standard page:
/// @dev NFTs assigned to zero address are considered invalid, and queries
/// about them do throw.
In other words, the ownerOf()
function is supposed to revert if you're querying a non-existing token ID.