1

I am new to solidity and to smart contracts, i couldn't find a great resource describing how the execution of a function in the future really work behind the scenes and how to implement it. I'd appreciate any help

0

3 Answers 3

1

It's not possible to schedule a future execution from Solidity.

However, its possible to schedule a future execution from outside Ethereum. For example, you could use an external system like Ethereum Alarm Clock to schedule a future execution. It will also require you to add a certain interface (function) in your smart contract to be compatible with the Ethereum Alarm Clock.

1
1

You can create a timestamp or block.number dependent function in solidity.

But you still have to activate it from an outside transaction when you want it execute at the time of or time after.

What that would look like is the following in pseudo code.

// in your function body
if(blockOrTimeReached()) {
    doScheduledTask()
}

Or it could be a modifier placed upon that function.

modifier checkScheduled() {
    if(blockOrTimeReached()) {
        doScheduledTask()
    }
    _;

}

function simpleTask() public checkScheduled returns (uint256) {
    // code here
}

This, of course, is highly dependent on your use-case.

1
0

This functionality is not possible natively in ethereum, you need to use external services like Oraclize, Aion scheduling System or EAC.

This answer shows a list of the available services with pros and cons: How can a contract run itself at a later time?

Hope this helps

1

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