0

Answer given here does not provide full solution.

Can some one please suggest me if it is practically feasible to execute a method in my smart contract every 24 hours using Ethereum Alarm Clock? You may refer the example given in the post linked above.

According to this doc, it is not possible to execute same call again after 255 block time (see gracePeriod parameter)

Kindly verify if my understanding is correct.

marked as duplicate by shane, Ismael, flygoing, Achala Dissanayake, Briomkez Jan 27 at 16:21

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.

1

You can execute recurrent calls using Ethereum alarm clock. The gracePeriod that is described in the links that you provide indicates how many blocks you will allow the executor to be delayed (maximum). That is, assume you want something to be executed in block x, the gracePeriod indicates that you are Ok with your call being executed at any block between x and x + gracePeriod. After x + gracePeriod is considered to late and the call will not be executed.

So it will work.

On the other side, you have alternatives to EAC, that are less expensive in gas (an ether transaction is about 500K gas in EAC, which is now rebuilt by Chronologic) and also Aion hs fixed fees. The Aion scheduling system has fees of about 10 cents od dollar per call, the first call you do is about 250Kgas and after that, the cost for a call goes as low as 70K (5x less that EAC). This is because the system creates accounts for the users. You can test it on ropsten.

This code shows how to set up a recurrent call (every day) using Aion Scheduling system:

pragma solidity ^0.4.24; 

// interface Aion
contract Aion {
    uint256 public serviceFee;
    function ScheduleCall(uint256 blocknumber, address to, uint256 value, uint256 gaslimit, uint256 gasprice, bytes data, bool schedType) public payable returns (uint,address);

}

// Main contract
contract MyContract{
    uint256 public sqrtValue;
    Aion aion;

    constructor(uint256 number) public payable{
        scheduleMyfucntion(number);
    }

    function scheduleMyfucntion(uint256 number) public {
        aion = Aion(0xFcFB45679539667f7ed55FA59A15c8Cad73d9a4E);
        bytes memory data = abi.encodeWithSelector(bytes4(keccak256('myfucntion(uint256)')),number); 
        uint callCost = 200000*1e9 + aion.serviceFee();
        aion.ScheduleCall.value(callCost)( block.timestamp + 1 days, address(this), 0, 200000, 1e9, data, true);
    }

    function myfucntion(uint256 number) public {
        // do your task here and call again the function to schedule
        scheduleMyfucntion(number);
    } 

    function () public payable {}

}

You can find more details here and here

Hope this helps.

  • When I tried to deploy this contract on Ropsten Network, it failed! I got "Gas Estimation limit failed" at the time of deploy. – Gagan Nov 6 '18 at 7:16
  • @Gagan, I fixed the code. The word payable in the constructor was missing and this code requires you to send ether when deploying as it schedules immediately the next call. You can send as little as 0.01 ether when deploying and this will keep this contract running for a long time. Let me know if you have any other issues. I deployed this contract on ropsten and is running so you should not find any other issues. Let me know. – Jaime Nov 6 '18 at 9:55
  • Thanks! I was able to deploy the contract successfully. I created a uint256 type global variable and incremented every time myfunction() is called. I can see neither new transactions nor the variable set to an incremented value. I'm not sure if my scheduled call is every being called. Can you please help me figure out what's happening? – Gagan Dec 7 '18 at 9:11
  • Also, what does the constructor parameter "number" doing in this code? – Gagan Dec 7 '18 at 9:14
  • it would be great if you have a look at this post here. – Gagan Dec 7 '18 at 9:47
1

The "Ethereum Alarm Clock" is not really meant to fire multiple times. It's meant for one job - 1 call.

You can however "recursively" link multiple executions automatically, by having the "clock contract" execute a method in one of your contracts that "does the job you need" then "queries the clock and queues another job" until it runs out of "gas".

But honestly that's not really the best solution for it.

You could for example make it a lot simpler ( and less expensive ), by "queueing up jobs, for a few days / months in advance, when the gas price is low".

There's another trick you can use, which is "storing gas in advance, that you can later use for a discount" see https://gastoken.io/ for details.

But the simplest and cheapest thing you can do, is have a daemon / cron that queries current gas price, creates a transaction and executes what you need when you need it. ( add gastoken in the mix for cheaper daily cost )

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