Hi,
Can anyone explain how to implement in an erc20 contract a function that when a transaction is executed, checks how much time has passed since the deployment of the contract and, based on predetermined intervals, allows or not to execute the transaction over a certain amount?
Example:
From deploy to 1 hour = maxTxamount 10
From 1 hour after deploy to 1 day = maxTxamount = 5
Etc.
Any code example? Thank you all
You can define a contract variable and store in it the deployment time obtained from block.timestamp
in the contract constructor. When this function executes, you can use block.timestamp
at the time the function is executing, and based on the difference between that and the deployment timestamp you stored before, set this limit.
Try writing the code based on this idea and show us the result.
Yes, this is even my idea, so the example can be:
uint public _deployTime = block.timestamp;
uint256 _maxTxBefore = 50;
uint256 _maxTxAfter = 100;
Than inside _transaction() function:
uint nowTime = block.timestamp;
if ((nowTime - _deployTime) < 60) {
require(amount <= _maxTxBefore, “Tx exceede Max”);
} else {
require(amount <= _maxTxAfter, “Tx exceede Max”);
}
Could this be a good solution or is it better to just use one maxTx variable and change its value? I believe that in that case it should be included in a transaction, so maybe my solution is the ideal one?
Yeah that looks good!