Oraclize对于以太坊来说,是一份智能合约,继承它之后,自定义的合约可以通过api访问外部的数据。但需要给一定的费用。
Orcalize的数据源有:
Orcalize的数据源调用的费用:
/*
Youtube video views
This contract keeps in storage a views counter
for a given Youtube video.
*/
pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract YoutubeViews is usingOraclize {
string public viewsCount;
event newOraclizeQuery(string description);
event newYoutubeViewsCount(string views);
function YoutubeViews() {
update();
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
viewsCount = result;
newYoutubeViewsCount(viewsCount);
// do something with viewsCount. like tipping the author if viewsCount > X?
}
function update() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query('URL', 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(@class, "watch-view-count")]/text())');
}
}
/* WolframAlpha example This contract sends a temperature measure request to WolframAlpha */
pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract WolframAlpha is usingOraclize {
string public temperature;
event newOraclizeQuery(string description);
event newTemperatureMeasure(string temperature);
function WolframAlpha() {
update();
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
temperature = result;
newTemperatureMeasure(temperature);
// do something with the temperature measure..
}
function update() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("WolframAlpha", "temperature in London");
}
}