Building a Query
In this section, we'll demonstrate how to build an on-chain query using the example of accessing credentials-protected CoinMarketCap price data, as discussed earlier in this documentation.
1. Registering the Request Components
The first step is to register each component of the query separately to create a unique feedID
. This involves:
HTTPRequest: Specify the method, host, path, headers, and parameters.
HTTPPrivatePatch: Include the encrypted API key.
JQFilter: Define how to filter and process the response.
ResultSchema: Specify the data format (e.g.,
int256
for integer values).
Each of these components can be registered using the smart contract functions. For example:
2. Saving the feedID
feedID
Once the request components are registered, the feedID
is generated by saving the combined request components:
3. Querying the Oracle
To query your request to the oracle, use the queryOracle
function with the following parameters:
feedId
: The unique identifier for the registered query components, specifying the data source and processing instructions. We've demonstrated how to calculate the feedId value in the previous sectionlogContractAddress
: A hardcoded value obtained from public sources, based on the network you're using and the log type (ILog
for general data orILog32
for fixed-width integer data).callbackAddress
: The address of the contract where the callback function will be executed after data retrieval.callbackSignature
: The function selector for the callback function, indicating which function to call with the retrieved data.
This function triggers the off-chain execution flow, sending the query details to the TEE for processing. The signed response is then returned on-chain by our oracle network and verified within the smart contract, ensuring it comes from a secure source and that no incorrect data can be saved in the data log.
Last updated