Hot answers tagged

84

Lazy vs Eager Execution There are two fundamental ways of designing a contract to be called at a later time: lazy evaluation or eager evaluation. Lazy evaluation means that the contract's state will be updated only when needed. This often makes sense for contracts that naturally incentivise users to call them at a future date. An example of this might be ...


20

You could use the Ethereum Alarm Clock as previously mentioned, but you could also change your programming style to a "must call to execute" paradigm. For instance, if you want to lock up money for a month until it gets returned, instead of actually having the money be sent after a month, you could have the user call a function that then returns the money.


15

As others have mentioned already, you can use the Alarm-clock or change the flow of your contract. Another option is to use Oraclize with an empty query: /* Simple Alarm code. This contract will be called back automatically 1 day after its birth */ import "dev.oraclize.it/api.sol"; contract Alarm is usingOraclize { function Alarm() { ...


14

Yes, you can guarantee long run time accuracy. Miners can't cheat that much to change the timestamp over days. Blocktime is adjusted to be constant within certain error margins, and timestamps is guaranteed to be rejected if they are excessive. Serenity and PoS 'proven' until core team decides otherwise. It is very very unlikely to happen, what reason could ...


13

When a transaction is executed, it is done in the context of being part of a block. The block includes a timestamp (in seconds since 1970), which your contract code can refer to by the name now. The timestamp is set by the miner who mines the block and nobody can be sure at what time they really mined it, so it may not be exactly accurate. However, it must ...


8

now is a Solidity special variable, which equates to the current time since the epoch, in seconds. From the documentation (linked above): now (uint): current block timestamp (alias for block.timestamp)


5

It's worth noting that miners can manipulate now and so it shouldn't be relied upon for anything sensitive such as seeding Psuedo-Random Number Generators.


5

You have to do it without relying on anything that triggers at that moment. You use the block.number to decide if bets are allowed. function isOpen() { return(block.number <= deadline); } function bet( ... { require(isOpen()); ... } You determine a winner retroactively. function didIWin( ... { if(!isOpen()) return false; return winner() ==...


5

No, In solidty there is no Date object which will give you the actual time, we can only get the timestamp of the block in which the contract is invoked, which is deterministic. You can use now keyword or block.timestamp in solidity to get the timestamp of the current block. This can be used to work with time. Reference to an auction contract is here.


5

The miner could cheat in the timestamp by a tolerance of 900 seconds. so if you check outside this intervall you are safe.


5

If you do want functions within a contract to be automatically triggered then you can use the ethereum alarm clock. Note this is not a core feature of Ethereum but rather a market where people are paid to execute a scheduled call and therefore there is no guarantee that your function will be called.


5

I believe this was designed as a feature to minimize the burden on the network and reduce resources. There are several solutions if you want to "call on a contract": http://www.ethereum-alarm-clock.com/ Source: I'm proud to announce the launch of the Ethereum Alarm Clock service. http://www.ethereum-alarm-clock.com/ The Alarm service ...


4

There is no formal way to schedule events via the protocol itself. However somebody already wrote an Ethereum Alarm Clock-contract that supports scheduling events at a later moment in time. It's decentralized as well as far as I could tell, anybody can fire scheduled events and get paid for doing so.


4

Is it possible to add email notification triggers into a smart contract? Not directly. You'd need a third party service that is watching the blockchain and then sends an email if it sees some condition happen. Alternatively, you could build such a service yourself. You'd need to be very careful your service isn't abused for spam floods. This is why such ...


4

The idea is that it creates a market for people with servers to "wake" other people's contracts up. The way it works is that your contract registers itself with the alarm clock, and pays a small fee. Other people can then call the alarm clock, which routs their call to your contract, "waking" your contract up. These people are paid a part of the fee you ...


2

Solution The protocol changed since the question was posted. It is possible to do recursive calls by building a service that for example takes advantage of Proxy wallet (to fund following calls). Ethereum Alarm Clock has RecurringPayment example in its repository. This is the contract: pragma solidity 0.4.24; import "contracts/Interface/...


2

Yes, Ethereum Alarm Clock is alive and well. It's on mainnet. In the first few months it transferred more than 1000 ETH safely. It has also been audited by BokkyPooBah. There's also new page: https://www.ethereum-alarm-clock.com/. Ethereum Alarm Clock is also integrated as Send Later button in MyCrypto. Here's tutorial how it works. Using MyCrypto or ...


2

I think they're reviving it. The new gitter is https://gitter.im/ethereum-alarm-clock/ethereum-alarm-clock.


2

Based on their gitter, no. The service is currently inactive. https://gitter.im/pipermerriam/ethereum-alarm-clock. Best to get in touch with https://github.com/pipermerriam/ to check on a reboot schedule.


2

All times in the blockchain are stored in Unix epoch format (How to calculate with time and dates?). The timestamp of execution can be retrieved with keyword now. So basically you just need to convert your start/end dates into Unix epoch timestamps and then compare them to now. You can also consider measuring elapsed time with block numbers (some ...


1

Time is an interesting thing on the blockchain. The two choices are to use time (or timestamp) and the block height. Block number is generally not advised, as the average block time is 15s. Because it is average, this means that blocks could be shorter (1s) or longer (1 min+). Depending on your application, this variance could mess up your calculations. ...


1

The version you linked (0.7.0) was released in the 31st of January, 2016. At that time, the latest Solidity release was 0.2.1 (30th of January, 2016). If you switch your compiler version to that Solidity release on the Remix IDE, the contract will compile just fine. You can find a working ETHFiddle snippet here. Keep in mind that the Ethereum Alarm Clock ...


1

On one of the major test nets, it's impossible to know the precise time that a block is generated because miners' clocks don't have to be perfectly accurate nor do the timestamps included in blocks need to be correct (they do need to be non-monotonic-decreasing from the last timestamp and less than 900s in the future). However, you can put an upper bound on ...


1

There is a way to do this. The contract can get the time directly but cannot execute itself. You can use services like Chronos, which allows you to schedule calls to your contract in a simple way. You will find examples of how to do exactly what you are asking for here look at the examples. This can be used on Rinkeby for testing. You can, for instance, ...


1

There is no way to have timers in smart contracts. You'll have to write a script off-chain that sends a transaction to the contract telling it to withdraw. Alternatively you could just forward all payments to the contract to your address.


1

At the moment I'm writing this answer it is: 1072718 seconds to the end of the current year in the timezone +12, block number 4757253 in Ethereum mainnet, so we will be at the block number 4820354 by the very end of this year. As avg I took 17 seconds as the author mentioned in his question, but etherscan says release frequency of the block is 14.76s Avg ...


1

Try https://github.com/pipermerriam/ethereum-datetime. It works with a unix-style uint timestamp under the hood. You get a DateTime object with year, month, day, hour, minute, second and even the weekday.


1

Gas assumption issue might be there? I guesstimate as long as "this function capable accepting fund for Gas", this scheduled contract would run forever.


1

Yes, you can use the blockchain2email.com API to send emails. If you would like to schedule notifications at a set time, you can use the Oraclize API to call email sending. Here is an example: import "dev.oraclize.it/api.sol"; contract blockchain2emailAPI {function SendEmail(string x, string y) returns(bool) {}} contract Alarm is usingOraclize { ...


1

Currently There are several options for this. The top answer is old and Ethereum Alarm Clock was down for a long time until a few weeks ago and now is managed (looks like) by the Chronologic team. I am copying an answer here as the community sends any other answer about scheduling to this one. I am including also a code example of how to do this with the ...


Only top voted, non community-wiki answers of a minimum length are eligible