2

I want to write a solidity function like

 function func(uint n, parameters*) payable public {

 ""wait n seconds""

 other statements  
 }

Is it possible? It seems that delay parameter in oraclize_query gives the partial answer, but it limits to no bigger than 60 days. Is there any solution for this task for arbitrary n?

Thanks in advance.

6

There is no concept of delay on solidity or ethereum. The VM runs the code in its own speed, and the final state is the only thing viewable on the blockchain (even if a function took some time to run, you wouldn't be able to see it while running).

When you're using oraclize, you're giving an out-of-blockchain process an instruction to do something, which might include a time delay, but on the blockchain itself it's impossible.

3

Yes, you can achieve the delay action in solidity using ethereum alarm clock contract. It will trigger the action after n seconds or days. you can refer ethereum alarm clock for more info. They have their contract deployed in Ropston test, so you can also test it before going for live.

2

This in not per se possible, because it would cause a loop checking on the time (which would require a very high amout of gas). Every miner is running your script on his mining device and you couldn't expect them to "wait".

You could consider the time variables to build a timer with multiple function calls. But the now Variable is only an alias for block.timestamp which won't help you if you only want to make one function call.

But you could build an external listener/oracle which sets a variable (e.g. in python with web3.py). This Variable is checked by a modifier in the second part of the function.

modifier timerOver()  {
   require(timerExpired == true);
   _;

function firstFunction(uint n, parameters*) payable public {
   emit startTimer(msg.sender, funcName);
}

function secondFunction(uint n, parameters*) timer public {
   // other statements 
}

In your python script you have a filter running on the startTimer-Event which triggers the change of the variable after an amount of time.

I hope this could help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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