简体   繁体   English

当有人转移时,我如何在 erc721-contract 中写时间戳

[英]how to I write timestamp in erc721-contract when someone transfer it

I want to know when the current owner has this token by storing a new timestamp every time an erc721 token is traded.我想通过每次交易 erc721 令牌时存储一个新的时间戳来知道当前所有者何时拥有此令牌。 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.每当执行 transferFrom 和 safeTransferFrom 时,我想在我的合同中存储一个时间戳(例如字符串时间戳 =“20220430”),请告诉我最好的方法。 My contract inherits from ERC721A(AZUKI standard).我的合同继承自 ERC721A(AZUKI 标准)。

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:并在两种方法中的任何一种上发出它,使用block.timestamp获取时间戳:

emit TransferTimestamp(tokenId, msg.sender, to, block.timestamp);

Note: block.timestamp is inaccurate.注意: block.timestamp不准确。 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.或者,您可以使用所有 EIP-721 NFT 中存在的内置Transfer事件。 The event list has the block when it was emitted, which can then be converted to a timestamp in the DApp's frontend.事件列表在发出时具有块,然后可以在 DApp 的前端将其转换为时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM