Last updated
Last updated
In this example, we show how to make a simple request to Sight Oracle and get the response.
Contract Initialization:
The Example
contract imports the necessary modules from the Sight Oracle package.
The contract uses the RequestBuilder
library to construct requests and the ResponseResolver
library to interpret the responses.
Constructor:
The constructor initializes the contract with the address of the Sight Oracle. This address is used to send requests and handle callbacks.
makeRequest Function:
This function initiates a new request to the Sight Oracle.
A new request is created using RequestBuilder.newRequest
, specifying the sender, the number of steps in the computation, the address to which the callback should be sent, and the callback function.
The rand
function is called to generate a random encrypted value and store it in the Sight Network.
The complete
function finalizes the request build process.
The send
function sends the request to the Sight Oracle.
callback Function:
This function is called by the Sight Oracle once the computation is complete.
It decodes the returned value using the ResponseResolver
and stores the encrypted target value in the _target
variable.
Modifiers:
onlyOracle
: Ensures that only the Sight Oracle can call the callback
function.
By following this guide, you can easily make a request to the Sight Oracle and handle the response securely and efficiently.