'How to identify Who holds an NFT for how long?

I am developing an NFT collection using ERC721 token. But I would like to know how a particular nft is held by a particular customer?

I am sensing there are two selling option one is minting fropm my website another one is buying from opensea?

Is that any way I can do that?



Solution 1:[1]

The ERC-721 contract uses this mapping(uint256 => address) private _owners; to store the owner. If you want to keep track of how long an address has holded a particular NFT you can create a struct

struct Owner {
  address ownerAddress;
  uint256 sinceWhen;
}

You then need to modify some functions (like mint, transfer, ...) and you set the sinceWhen as the block.timestamp.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Niccolò Fant