0

I have a simple contract that receives any amount of ETH. The contract keeps those ETH certain amount of time until it realeases the funds to it's original owner.

I have defined which block represents the moment of release.

The only thing that I don't know how to do is, how to tell the contract: "now we are in the specified block, release those ETH".

I mean, the contract is not reading the blockchain continuously, which is the way to tell that info to the contract automatically?

1

A contract cannot execute itself at a later time, see How can a contract run itself at a later time?.

A common workaround is to use a "withdraw" pattern. You do not credit the value at a given block, but only the interested party has to ask for it.

address constant creditor = 0x123412341234...;
uint constant creditBlock = 4000000; 
uint constant creditAmount = 1 wei;

function withdraw() public {
    // Ensure only "creditor" can call the function
    // and after a target block number has been mined
    if (msg.sender == creditor && block.number >= creditBlock) {
        msg.sender.transfer(creditAmount);
    }
}
1

You could use any of the services available to schedule executions of functions. You can use:

Ethereum Clock Alarm.
Oraclize
Chronos

Disclaimer: I wrote the Chronos code and it is available only on Rinkeby for now, so you can use it for testing. The advantage is that it is really simple to use.

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.