// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IERC721 {
function ownerOf(uint256 tokenId) external view returns (address);
function transferFrom(address from, address to, uint256 tokenId) external;
}
/// @title NFT Ownership Verification and Secure Transfer Contract
/// @dev Enables verification and secure peer-to-peer transfers
contract NFTOwnershipVerifier {
event OwnershipVerified(address indexed user, uint256 indexed tokenId);
event NFTTransferred(address indexed from, address indexed to, uint256 indexed tokenId);
/// @notice Verifies if a user owns a specific NFT
/// @param nftContract Address of the ERC-721 contract
/// @param tokenId ID of the NFT
/// @param user Address of the potential owner
/// @return bool Whether the user owns the token
function verifyOwnership(address nftContract, uint256 tokenId, address user)
external
view
returns (bool)
{
IERC721 nft = IERC721(nftContract);
bool isOwner = nft.ownerOf(tokenId) == user;
if (isOwner) {
emit OwnershipVerified(user, tokenId);
}
return isOwner;
}
/// @notice Securely transfers an NFT between two users
/// @param nftContract Address of the ERC-721 contract
/// @param tokenId ID of the NFT
/// @param from Current owner of the NFT
/// @param to New recipient of the NFT
function secureTransfer(
address nftContract,
uint256 tokenId,
address from,
address to
) external {
IERC721 nft = IERC721(nftContract);
require(nft.ownerOf(tokenId) == from, "Sender does not own the NFT");
nft.transferFrom(from, to, tokenId);
emit NFTTransferred(from, to, tokenId);
}
}