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 TimeOfTransfer
using now
somewhere (where ? I need a place where it can't be tempered with or frauded) , then substract it from the next now
call 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;
}