So I'm learning solidity and wanted to make an erc-20 token after reading the solidity by example docs. Let's call the token T.

I would like to measure the elapsed time between two transfers of an arbitrary amount of T from the same erc-20 wallet ,and use this elapsed time later in the transfer function, for example charging a time based fee.

My idea was to store the value TimeOfTransferusing now somewhere (where ? I need a place where it can't be tempered with or frauded) , then substract it from the next nowcall at a future transfer, and thus get the elapsed time.

Also can this is done in a way that can't be gamed/faked while making the user pay for all gas ?

Maybe something like this. Should I add a if statement that controls at every transfer if it's the first or is there a way to store the time of the very first transfer of token T from that wallet ? If I return a 2-tuple (true, TimeofTransfer) in the transfer function, is it still an erc-20?

Sorry if this is overly specific, I couldn't find related answers.

function transfer(address to, uint tokens) public returns (bool success) {
    Elapsed = now - TimeOfTransfer 
    TimeOfTransfer = now
    balances[msg.sender] = balances[msg.sender].sub(tokens);
    balances[to] = balances[to].add(tokens);
    emit Transfer(msg.sender, to, tokens);
    return true;

1 Answer 1


As you pointed out your contract may get abused. Basically anything which relies on stuff which can be manipulated by users will be manipulated if the reward is good enough.

One thing you can think of is setting a required gas price for incoming transactions. So you can revert all transactions which don't have a gas price X. In that way nobody can game the system by making fast or slow transactions with different gas prices. However this doesn't mean that the timing couldn't be abused: an attacker might simply wait until network congestion is at a right level for the given gas price and then send his transaction.

Also the transfer function has to take the right parameters and return the right types so you can't modify the output if you want it to be ERC20 compatible. But nothing prevents you from storing such timeOfTransfer variable to the contract somewhere and getting that value with some other function - you are free to add any arbitrary functions to an ERC20 contract.


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.