Last active
October 6, 2022 12:53
-
-
Save bishesh16/f540218153ce67513aae3b6ccd578be2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.19; | |
import "./Oraclize.sol"; | |
contract SimpleOraclizeContract is usingOraclize { | |
string public ETHXBT; // XBT is a synonym of BTC | |
event LogConstructorInitiated(string nextStep); | |
event LogPriceUpdated(string price); | |
event LogNewOraclizeQuery(string description); | |
function SimpleOraclizeContract() payable { | |
LogConstructorInitiated("Constructor was initiated. Call 'updatePrice()' to send the Oraclize Query."); | |
} | |
function __callback(bytes32 myid, string result) { | |
if (msg.sender != oraclize_cbAddress()) revert(); | |
ETHXBT = result; | |
LogPriceUpdated(result); | |
} | |
function updatePrice() payable { | |
if (oraclize_getPrice("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("URL", "json(https://api.kraken.com/0/public/Ticker?pair=ETHXBT).result.XETHXXBT.c.0"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment