![](/img/trans.png)
[英]MintTo contract from web3 gives error - ERC721: transfer to non ERC721Receiver implementer
[英]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.