Solidity

如何在特定時間發送 eth?

  • May 17, 2018

如何在特定時間發送 eth?

如果 ICO 眾籌從 UTC 時間 9:00:00 開始,我如何在 9:00:00 準確地發送 eth 時製作 txid?

您可以使用具有計算延遲的雙 Oraclize 查詢。

這工作如下:

pragma solidity ^0.4.XXX;

   import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";

   contract ExampleContract is usingOraclize {

       uint public time;
       uint public delay;
       uint public desired_time; // 9:00 of desired day/month and year on UNIX time format
       event LogConstructorInitiated(string nextStep);
       event LogTimeUpdated(string time);
       event LogNewOraclizeQuery(string description);

       function ExampleContract() payable {
           LogConstructorInitiated("Constructor was initiated.");
           delay = 0;
           updateTime();
       }

       function __callback(bytes32 myid, string result) {
           if (msg.sender != oraclize_cbAddress()) revert();
           time = parseInt(result,0);
           LogTimeUpdated(result);
           if(time < desiredtime)
             delay= desiredtime - time;
               updateTime();
           else if(time == desiredtime || time > desiredtime){
               //do what you want to do at 9:00
           }

       }

       function updateTime() payable {
           if (oraclize_getTime("URL") > this.balance) {
               LogNewOraclizeQuery("Oraclize query was NOT sent, please add some 
               ETH to cover for the query fee");
           } else {
               LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer..");
               oraclize_query(delay, "URL", "xml or json(parsing of the xml or json").parse.parse....;

           }
       }
   }

我快速完成了程式碼,可能需要快速修改,但這樣你就可以很好地了解你可以/必須做什麼。

希望能幫助到你!

我相信你現在最好的選擇是乙太坊鬧鐘

引用自:https://ethereum.stackexchange.com/questions/48696