0

This question already has an answer here:

I am developing a simple application that should work only in a specific time, lets say between 0800 hrs and 1600 hours. How can I do it. That means. The contract should start by itself at 0800 and stop by 1600 everyday. The user should not be allowed to do any transaction other than this time.

marked as duplicate by Richard Horrocks, Achala Dissanayake, shane, flygoing, Rosco Kalis Feb 18 at 20:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Hi there. I've suggested a duplicate to your question, but I should have first asked for clarification on what you're asking. Do you mean you want a contract to effectively run itself only between those times, or do you mean that you only want to allow users to be able to run your contract (via transactions) between those times? – Richard Horrocks Feb 18 at 14:48
  • Thanks for your response. Is there any tutorial which explains more. Any route is appreciable. – chandru Feb 18 at 14:51
  • I have edited my question. – chandru Feb 18 at 14:54
0

Referring to the highest answer to the question linked by Richard, I think you want the "Lazy" way suggested. How can a contract run itself at a later time?

The contract would check the currentime to figure out of its between "office hours" and just reject transactions if not.

There'll be interesting expressions to work out the start and stop times given what we have to work with: (https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=block#block-and-transaction-properties)

block.timestamp (uint): current block timestamp as seconds since unix epoch

Approximately:

function todayStart() public view returns(uint) { 
  return funkyCalculation;
}
function todayStop() public view uint() { ...

modifiers onlyOfficeHours {
  require(now >= todayStart && now < todayStop);
  _;
}

function doSomething() public onlyOfficeHours { ...

Hope it helps.

function

  • Thanks for your answer. Well, I couldnt understand your answer clearly. Is there any tutorial or something for that? – chandru Feb 20 at 3:30
  • 1
    It's a tough problem if you're just starting out. It involves digesting some ideas that may be hard to accept. A contract doesn't run in the background and it can't be written in such a way that it's triggered at a certain time. It must be started by an external signed message. It can be written in such a way that it rejects such requests outside "office hours". – Rob Hitchens - B9lab Feb 20 at 5:18
  • Thanks for your valuable information – chandru Feb 21 at 13:45

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