没有销毁NFT之前可以正常获取所有者名下所有的NFT数组,如果销毁了名下的一个NFT ,就无法获取到数组 怎样才能正常获取销毁后所有者名下的所有NFT数组。
function burn(uint256 tokenId) public virtual{
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved");
_burn(tokenId);
burnshu++;
}
function getByOwner(address_owner)external view returns(uint[] memory) {
uint[] memory result = new uint[](balanceOf(_owner));
uint counter = 0;
for (uint i = 1; i <= balanceOf(_owner); i++) {
if (ownerOf(i) == _owner&&_owner != address(0)) {
result[counter] = i;
counter++;
}
}
return result;
}
开始可以正常获取
销毁了一个NFT后,就不能正常获取了提示: The transaction has been reverted to the initial state. Reason provided by the contract: "ERC721: owner query for nonexistent token". Debug the transaction to get more information.