3 ms·
The Ethereum blockchain is reactive, it only performs any effects when someone makes a transaction. So you can't directly do something like a timer. So, for ex
by mbrock 9y ago
The Ethereum blockchain is reactive, it only performs any effects when someone makes a transaction. So you can't directly do something like a timer.
So, for example, with crowdfund contracts that have an expiration time, you would typically just make it so that after the expiration time, if the crowdfund didn't succeed, then everyone can reclaim their funds. They aren't refunded automatically; you need some user action to trigger anything.
It would be possible to have a single "refundEveryone" method which would send all the funds to everyone when anyone called it. But if there were thousands of participants, this function would be expensive to call, and possibly even too expensive for the network's limits.
The standard solution to this limitation is that you just have to incentivize people to call your contract at the right time. So you can for example make it so that whoever is the first to call the contract after the deadline gets a reward. Then you publish that and hope someone will do it.
(A simpler solution is to just run a cronjob on your own computer...)