Skip to content

Instantly share code, notes, and snippets.

@bishesh16
Last active October 6, 2022 12:53
Show Gist options
  • Save bishesh16/f540218153ce67513aae3b6ccd578be2 to your computer and use it in GitHub Desktop.
Save bishesh16/f540218153ce67513aae3b6ccd578be2 to your computer and use it in GitHub Desktop.
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