2

Is there a method to wait a certain amount of seconds in idle?

I want to simulate a production process within a prototype smart contract and therefore i want to wait 5 seconds to represent this process.

2

1 Answer 1

2

You cannot pause the execution of a smart contract directly. If a sleep instruction was part of the protocol, it would be a huge security risk to Ethereum because it could be used to slow down miners so much that the network would become unusable.

And even if you could, you wouldn't notice it because the results of a contract execution are written into the blockchain when the block is mined. Waiting for a confirmation takes a random amount of seconds anyway. (on average about 15 seconds, which is more than your 5)

There is a way to have a function of your Solidity contract executed at a later time:

http://www.ethereum-alarm-clock.com/

But you're not going to get it to be precisely 5 seconds.

I would recommend waiting 5 seconds in the client-side code that uses your contract, instead of trying to wait 5 seconds in Solidity directly.

2
  • Okay thank you for your answer. I have to find an other way to simulate a production process. Because of my noob status in developping Smart Contracts, do you have any recommandations for tutorials, which can show me how to read logs and call functions of my smart contracts from external scripts?
    – TimRicta
    Sep 14, 2017 at 13:14
  • @TimRicta I have been using the web3.js JavaScript library to develop user interfaces for smart contracts. You can use it to call the functions in the smart contracts with JavaScript from a browser. I don't know about tutorials, but you can read a reference here: github.com/ethereum/wiki/wiki/JavaScript-API
    – Jesbus
    Sep 14, 2017 at 13:18

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.