To send a query to Oraclize, you will need to call the oraclize_query function. This function expects at least two arguments, that is, the data source and the input for the given data source. The data source argument is not case-sensitive.
Here are some basic examples of the oraclize_query function:
oraclize_query("WolframAlpha", "random number between 0 and 100");
oraclize_query("URL", "https://api.kraken.com/0/public/Ticker?pair=ETHXBT");
oraclize_query("IPFS", "QmdEJwJG1T9rzHvBD8i69HHuJaRgXRKEQCP7Bh1BVttZbU");
oraclize_query("URL", "https://xyz.io/makePayment", '{"currency": "USD", "amount": "1"}');
Here is how the preceding code works:
- If the first argument is a string, it is assumed to be the data source and the second argument is assumed to be the input for the data source. In the first call, the data source is WolframAlpha and the search query we sent to it was random number between 0 and 100.
- In the second call, we make an HTTP GET request to the URL present in the second argument.
- In the third call, we fetch the content of the QmdEJwJG1T9rzHvBD8i69HHuJaRgXRKEQCP7Bh1BVttZbU file from IPFS.
- If two consecutive arguments after the data source are strings, then it's assumed to be a POST request. In the last call, we make an HTTP POST request to https://xyz.io/makePayment and the POST request body content is the string in the third argument. Oraclize is intelligent enough to detect the content-type header based on the string format.