I want to have my smart contract call a function every 24 hours automatically. Can this be achieved as follows?
pragma solidity ^0.4.2;
import "http://github.com/oraclize/ethereum-api/oraclizeAPI_0.4.sol";
contract MyContract is usingOraclize {
function callThisToStart() {
oraclize_query(1*day, "URL", "");
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
doSomething();
callThisToStart();
}
function doSomething() {
// then this should run every 24 hours
}
}
I don't understand how Oracle works yet so this may be completely wrong - callThisToStart()
would be called, which would then run the __callback
function a day later, which will then run some code in doSomething()
and call callThisToStart()
afterwards so the process would be repeated in a day.