I want to know when the current owner has this token by storing a new timestamp every time an erc721 token is traded. I want to store a timestamp (ex. string timestamp = "20220430") in my contract whenever transferFrom and safeTransferFrom are executed, please give me an idea of the best way. My contract inherits from ERC721A(AZUKI standard).
My suggestion is to add an event:
event TransferTimestamp(uint256 tokenId, address from, address to, uint256 timestamp);
And emit it on either of the two methods, using block.timestamp
to get the timestamp:
emit TransferTimestamp(tokenId, msg.sender, to, block.timestamp);
Note: block.timestamp
is inaccurate. Miners are directly able to influence its value with no checks.
Alternatively, you could use the built-in Transfer
event present in all EIP-721 NFTs. The event list has the block when it was emitted, which can then be converted to a timestamp in the DApp's frontend.