What is the standard way to delay the payment of an ERC20 token?


I am looking for a way that a user would pay for my ERC20 token in ETH, then an arbitrary number of days later, lets say 7 days, they would receive the tokens.

How is this usually achieved in Solidity?

I have read in the docs that that date/time handling is done with block.timestamp

Some example code I have found is:

function f(uint start, uint daysAfter) {
    if (now >= start + daysAfter * 1 days) {
      // ...

but I am unsure on how to use it to trigger payment to a user after x days.


You can also do it with a withdraw pattern. When a user buys tokens you could store the amount purchased alongside the time of the purchase.

Then, the user can call the withdraw function whenever he wants, which will only allow the token transfer if the date is 7 days later than the purchase time you stored for that particular address.

If you do it this way, you can prevent problems and vulnerabilities that can appear if you schedule the calls or have the contract send tokens to multiple addresses at the same time.


One way you could achieve this would be by creating a struct

struct TokenSale{
    address recipientAddress;
    uint tokenAmount;
    uint timeStamp;

Then you would just create a new TokenSale and add it to an indexed array in storage. Then write some offline code in JS or python to check the current time minus the TokenSale's timestamp and if it is greater than 7 days, send a transaction handing over the tokens to the given address.

Best I could think of, hope this helps!


If you want to do it fully on chain, you can use something like http://www.ethereum-alarm-clock.com where you can schedule calls into the future. You could also use something like oraclize.it and schedule a callback from some point in the future (max. 60 days)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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