簡體   English   中英

當有人轉移時,我如何在 erc721-contract 中寫時間戳

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

我想通過每次交易 erc721 令牌時存儲一個新的時間戳來知道當前所有者何時擁有此令牌。 每當執行 transferFrom 和 safeTransferFrom 時,我想在我的合同中存儲一個時間戳(例如字符串時間戳 =“20220430”),請告訴我最好的方法。 我的合同繼承自 ERC721A(AZUKI 標准)。

我的建議是添加一個事件:

event TransferTimestamp(uint256 tokenId, address from, address to, uint256 timestamp);

並在兩種方法中的任何一種上發出它,使用block.timestamp獲取時間戳:

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

注意: block.timestamp不准確。 礦工無需檢查即可直接影響其價值。

或者,您可以使用所有 EIP-721 NFT 中存在的內置Transfer事件。 事件列表在發出時具有塊,然后可以在 DApp 的前端將其轉換為時間戳。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM