Random numbers/entropy from physical sources such as quantum/thermal processes: e.g., to fairly select a winner in a lottery smart contract
Parametric triggers indexed to natural hazards: e.g., triggering of catastrophe bond smart contracts, such as Richter scale measurements for an earthquake bond
Exchange rate data: e.g., for accurate pegging of cryptocurrencies to fiat currency
Capital markets data: e.g., pricing baskets of tokenized assets/securities
Benchmark reference data: e.g., incorporating interest rates into smart financial derivatives
Static/pseudostatic data: security identifiers, country codes, currency codes, etc.
Time and interval data: for event triggers grounded in precise time measurements
Weather data: e.g., insurance premium calculations based on weather forecasts
Political events: for prediction market resolution
Sporting events: for prediction market resolution and fantasy sports contracts
Geolocation data: e.g., as used in supply chain tracking
Damage verification: for insurance contracts
Events occurring on other blockchains: interoperability functions
Ether market price: e.g., for fiat gas price oracles
Flight statistics: e.g., as used by groups and clubs for flight ticket pooling
Collect data from an off-chain source.
Transfer the data on-chain with a signed message.
Make the data available by putting it in a smart contract’s storage.
Receive a query from a DApp.
Parse the query.
Check that payment and data access permissions are provided.
Retrieve relevant data from an off-chain source (and encrypt it if necessary).
Sign the transaction(s) with the data included.
Broadcast the transaction(s) to the network.
Schedule any further necessary transactions, such as notifications, etc.
publicclassSampleContractCryptlet:Cryptlet{publicSampleContractCryptlet(Guidid,GuidbindingId,stringname,stringaddress,IContainerServiceshostContainer,boolcontract):base(id,bindingId,name,address,hostContainer,contract){MessageApi=newCryptletMessageApi(GetType().FullName,newSampleContractConstructor())
/*ETH/USD price ticker leveraging CryptoCompare APIThis contract keeps in storage an updated ETH/USD price,which is updated every 10 minutes.*/pragma solidity^0.4.1;import"github.com/oraclize/ethereum-api/oraclizeAPI.sol";/*"oraclize_" prepended methods indicate inheritance from "usingOraclize"*/contractEthUsdPriceTickerisusingOraclize{uintpublicethUsd;eventnewOraclizeQuery(stringdescription);eventnewCallbackResult(stringresult);functionEthUsdPriceTicker()payable{// signals TLSN proof generation and storage on IPFSoraclize_setProof(proofType_TLSNotary|proofStorage_IPFS);// requests queryqueryTicker();}function__callback(bytes32_queryId,string_result,bytes_proof)public{if(msg.sender!=oraclize_cbAddress())throw;newCallbackResult(_result);/** Parse the result string into an unsigned integer for on-chain use.* Uses inherited "parseInt" helper from "usingOraclize", allowing for* a string result such as "123.45" to be converted to uint 12345.*/ethUsd=parseInt(_result,2);// called from callback since we're polling the pricequeryTicker();}functionqueryTicker()publicpayable{if(oraclize_getPrice("URL")>this.balance){newOraclizeQuery("Oraclize query was NOT sent, please add some ETHtocoverforthequeryfee");}else{newOraclizeQuery("Oraclize query was sent, standing by for theanswer...");// query params are (delay in seconds, datasource type,// datasource argument)// specifies JSONPath, to fetch specific portion of JSON API resultoraclize_query(60*10,"URL","json(https://min-api.cryptocompare.com/data/price?\fsym=ETH&tsyms=USD,EUR,GBP).USD");}}}
The supported data source to use, such as URL, WolframAlpha, IPFS, or computation
The argument for the given data source, which may include the use of JSON or XML parsing helpers
pragma solidity^0.4.11;contractOracle{uint256publicdivisor;functioninitRequest(uint256queryType,function(uint256)externalonSuccess,function(uint256)externalonFailure)publicreturns(uint256id);functionaddArgumentToRequestUint(uint256id,bytes32name,uint256arg)public;functionaddArgumentToRequestString(uint256id,bytes32name,bytes32arg)public;functionexecuteRequest(uint256id)public;functiongetResponseUint(uint256id,bytes32name)publicconstantreturns(uint256);functiongetResponseString(uint256id,bytes32name)publicconstantreturns(bytes32);functiongetResponseError(uint256id)publicconstantreturns(bytes32);functiondeleteResponse(uint256id)publicconstant;}contractOracleB1IQClient{Oracleprivateoracle;eventLogError(bytes32description);functionOracleB1IQClient(addressaddr)publicpayable{oracle=Oracle(addr);getIntraday("IBM",now);}functiongetIntraday(bytes32ric,uint256timestamp)public{uint256id=oracle.initRequest(0,this.handleSuccess,this.handleFailure);oracle.addArgumentToRequestString(id,"symbol",ric);oracle.addArgumentToRequestUint(id,"timestamp",timestamp);oracle.executeRequest(id);}functionhandleSuccess(uint256id)public{assert(msg.sender==address(oracle));bytes32ric=oracle.getResponseString(id,"symbol");uint256open=oracle.getResponseUint(id,"open");uint256high=oracle.getResponseUint(id,"high");uint256low=oracle.getResponseUint(id,"low");uint256close=oracle.getResponseUint(id,"close");uint256bid=oracle.getResponseUint(id,"bid");uint256ask=oracle.getResponseUint(id,"ask");uint256timestamp=oracle.getResponseUint(id,"timestamp");oracle.deleteResponse(id);// Do something with the price data}functionhandleFailure(uint256id)public{assert(msg.sender==address(oracle));bytes32error=oracle.getResponseError(id);oracle.deleteResponse(id);emitLogError(error);}}