I want to make a calculation with the blockchain every day at the same hour. Iknow every miners got his own time. I think i had to find an oracle. Any idea ?
2 Answers
Check https://www.ethereum-alarm-clock.com - that looks like what you need. Not affiliated.
Ethereum Alarm Clock was designed to incentivise the decentalized network of TimeNodes making sure your scheduled transaction will be executed on time.
You can write a function in your contract that does your calculation, then you can schedule the function to be executed in 24 hours using a service called Aion (aion.ethpanrhron.com).
There are a couple of examples of how to do this in the GitHub page (https://github.com/ETH-Pantheon/Aion/blob/master/README.md)
For instance:
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;
address aionAccount;
function schedule_sq(uint256 number) public {
aion = Aion(0x10999AE703401312798EA437b02A9849fa43E5AB);
bytes memory data = abi.encodeWithSelector(bytes4(keccak256('sq(uint256)')),number);
uint callCost = 200000*1e9 + aion.serviceFee();
uint256 txId;
(txId, aionAccount) = aion.ScheduleCall.value(callCost)( block.timestamp+1 day, address(this), 0, 200000, 1e9, data, true);
}
function sq(uint256 number) public {
sqValue = number**2;
schedule_sq(sqValue)
}
function () public payable {}
}
in this example a function (sq(uint256 number)
)that executes an square operation is called every 24 hours.
Aion has several advantages, being the most important that all the unused gas is returned.
You can get more information in the link above. Also is free to use on the testnet (ropsten)
Hope this helps.