1

This question already has an answer here:

How to automatically send ether, at regular intervals. I have an array of addresses. For example. 24 hours later send all addresses send eth. I can not understand how to make the timer on the solidity and send eth all adress.

All thanks in advance.

marked as duplicate by Nicolas Massart, niksmac, Matthew Schmidt, Community Jan 26 '17 at 16:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

Short answer: There's no timer. Something has to trigger the transaction to get it started and supply the gas so it can run. The Ethereum Alarm Clock is a cron-like solution for timed events. It involves sending it your callback and the time you need it to run and some Ether to pay for the gas. It's possible this is the timer solution you're looking for but I think I would be leading you astray in this case.

In my opinion, you should probably reverse the way you're thinking about this.

"send all addresses" implies a loopy process I wouldn't be comfortable with. There are possibly serious problems. Example, if the list is too long, the transaction will exceed the block gas limit and will be unable to run at all. Possibility of funds locked in a contract with no way out. There's a send() inside the loop. That means interacting with more than one untrusted contract at a time; another source of discomfort. Discomfort squared.

If you flip this thing around and make the addresses claim a withdrawal, both sources of discomfort, as well as the timing problem disappear. Clients can decide when they want to send a claim, and then your contract can decide if the claim is valid or not.

It's unclear if the clients are humans or bots but either case works on the same principle. You present a status function so they can know if a withdrawal is authorized (read only and free). You present a withdraw function so they can "pull" the funds out. They pay for the gas and also look after the timing.

Very sketchy outline:

function withdraw() returns(bool success) {
    // some details for you to work out
    if( msg.sender is owed money) {
        // use the safe send pattern
        if(msg.sender.send(amount) { ...
    }
}

function status() constant returns(bool authorized) {
    return (msg.sender is owed money);
}

Or in case all-or-nothing isn't the idea, let the user decide how much to withdraw:

function withdrawAmount(uint amount) returns(bool success) {
    if(msg.sender is owed that much or more) ...
}

function amountAuthorized() constant returns(uint amountAuthorized) {
    return authorized[msg.sender];
}

Hope it helps.

footnote. Just noticed Nicholas' comment. Of the two methods described in the post, I incline to the "lazy" method to avoid that loop.

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