I need a function in my contract to be executed daily by itself.
I know that Ethereum Alarm Clock and Oraclize do it but none of them worked for me.
For example this code using Oraclize
pragma solidity ^0.4.2;
import "http://github.com/oraclize/ethereum-api/oraclizeAPI_0.4.sol";
contract MyContract is usingOraclize {
uint public tmp = 0;
function callThisToStart() {
oraclize_query(60, "URL", "");
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
doSomething();
callThisToStart();
}
function doSomething() {
tmp++;
}
}
I do not really know why it does not work (tmp is not increased)
I do not care about using EAC or Oraclize, but I really want to get that for example every minute the value of a variable increases
Thank you.
Best Answer
Its not necessary to use Ethereum Alarm Clock and Oraclize if you just want to execute a function.
Lets get down to basic. What is a function?
Whichever variable you want to modify, you need not use it as a variable. Instead, you can declare that variable as a function, which returns the value on time variables of the blockchain, example,
blockNumber
,block.timestamp
.For answering your question, you can do the above described process by the contract given below.
This contract increases the value returned by
tmp
every minute. And there are separate functions to enable and disable this feature.