3
pragma solidity ^0.4.0;
contract Test {
uint[] timestamp;

function setTime(uint _timeToset) public returns(bool) {
    timestamp.push(now + _timeToset);
   return true;
}

function deleteEntriesBasedOnTime() public returns(bool) {
    for (uint i=0; i<timestamp.length;i++) {
        if (now == timestamp[i]) {
            delete timestamp[i];
            return true;
        }
    }
    return false;
}
}
3
  • 1
    do you want the contract to execute automatically at particular times?
    – Jaime
    Sep 9 '18 at 6:35
  • yeah.I want to execute the function at particular times.
    – MallRoy
    Sep 9 '18 at 7:09
  • I added a list of the active services that allow you to do this
    – Jaime
    Sep 10 '18 at 13:53
5

Ethereum smart contracts can't execute by themselves, especially at certain times. All smart contract executions are triggered by a transaction from outside the blockchain - so someone has to call some function in a contract to start the processing.

Here's some more info and ideas: How can a contract run itself at a later time?

7

@Lauri answer is correct but the link is by all means outdated.

There are several projects that are acting on the mainnet or testnets.

Aion by ETH-Pantheon:

This a system that allows arbitrary bytecode transactions to be scheduled.This means you can call a particular function in a contract with particular data at any time or block in the future.
Pros: simple, allows arbitrary bytecode, unused gas is returned, low gas consumption, trustless, the transaction fee is defined apriori, live in mainnet and test networks, nice App, transactions can be canceled without incurring in payment of any class.
Cons: centralized.


Chronologic network:

This is basically a wrap on ethereum alarm clock (reboot).
Pros: decentralized (as it uses EAC), allows arbitrary bytecode, unused gas is returned, nice app, live in mainnet and test networks .
Cons: expensive in gas, fee per transaction is not defined apriori, scheduler nodes need to hold a chronologic token, also beside the payment to the executor a basefee to the developer of the EAC should be provided.


Oraclize:

This works calling a callback function after some period selected by the user, then you put the code you want to execute inside that function.
Pros: simple, live in mainnet and test networks
Cons: centralized, no arbitrary bytecode allowed, gas unused is not returned, the fee per transaction could be changed at any time, and to any value, which mean you must trust Oraclize.


Joule System: mywish.io.

This is a decentralized system to schedule ether transactions.
Pros: decentralized, app, live on mainnet and test networks
Cons: limited type of transactions.

Hope this helps

1
  • Thanks for the heads up! :) Good to know things are progressing. Sep 10 '18 at 14:24

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.