Solidity
如何在特定時間發送 eth?
如何在特定時間發送 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....; } } }
- 在這裡,您可以獲得有關Oraclize 以及如何使用它的資訊:https ://docs.oraclize.it/#ethereum-quick-start-the-query-id
- 在這裡,您還有一個站點,您可以在其中以 UNIX 格式對目前時間進行 Oraclize 查詢:https ://timezonedb.com/api
我快速完成了程式碼,可能需要快速修改,但這樣你就可以很好地了解你可以/必須做什麼。
希望能幫助到你!
我相信你現在最好的選擇是乙太坊鬧鐘