0

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.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
chandru
  • 131
  • 1
  • 6
  • 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 '19 at 14:48
  • Thanks for your response. Is there any tutorial which explains more. Any route is appreciable. – chandru Feb 18 '19 at 14:51
  • I have edited my question. – chandru Feb 18 '19 at 14:54

1 Answers1

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

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
  • Thanks for your answer. Well, I couldnt understand your answer clearly. Is there any tutorial or something for that? – chandru Feb 20 '19 at 03: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 Feb 20 '19 at 05:18