Skip to content

Instantly share code, notes, and snippets.

@0x3bfc
Created January 3, 2019 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x3bfc/1f5c0e82c03a0bdb1d1dda2955ed854d to your computer and use it in GitHub Desktop.
Save 0x3bfc/1f5c0e82c03a0bdb1d1dda2955ed854d to your computer and use it in GitHub Desktop.
Oraclize.sol
import "github.com/oraclize/ethereum-api/oraclizeAPI_0.5.sol";
contract OracleExample is usingOraclize {
string public EURUSD;
function updatePrice() public payable {
if (oraclize_getPrice("URL") > address(this).balance) {
//Handle out of funds error
} else {
oraclize_query("URL", "json(http://api.fixer.io/latest?symbols=USD).rates.USD");
}
}
function __callback(bytes32 myid, string memory result) public {
require(msg.sender == oraclize_cbAddress());
EURUSD = result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment