I have to transfer tokens from one account to another and I would like to associate a timestamp with that tokens so that i can identify which token was transferred on which time.

How do we write this code in a smart contract?

2 Answers 2


You can just enrich your structure in order to store the timestamp.

Consider a simple mapping like this:

    mapping (address => uint256) public balanceOf;

to do something like you said would be enough to have a structure like this:

    struct Balance {
        uint amount;
        uint timestamp;

    mapping (address => Balance) public balanceOf;

and structure your code accordingly in order to save the timestamp together with the amount.


If you don't need the timestamp within the contract, you could just use the transaction block's timestamp. So whenever a token is transferred you can check in which block it was and check its timestamp.

But if you need to store the info in the contract itself then @mirg's answer will do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.