Upload Secrets to Oracle
In this section, we'll guide you through the process of securely uploading secrets to the Oracle. This process is essential when you need to include custom headers in the request that the Oracle will send to the target API.
Step 1: Approve a Consumer
Before you can upload secrets, you must first approve a consumer in the Oracle. A consumer is the entity that will be allowed to interact with the Oracle on your behalf. Or in other words is your contract deployed.
Once a consumer is approved, you will be able to attach secrets such as headers that will be included in any request the Oracle makes on your behalf.
Step 2: Upload Secrets via the Dashboard
After approving the consumer, go to the Upload Secrets section of the dashboard. Here, you'll be able to configure the headers and other secrets that the Oracle will use when making API requests.
-
Select Consumer:
First, select the approved consumer for which you want to upload secrets. -
Add Headers:
You can now add any custom headers that should be sent in the Oracle’s request to the target API. These headers might include authentication tokens, API keys, or any other sensitive information that needs to be securely transmitted.
Step 3: Sign Headers with Your Wallet
After configuring the headers, you'll need to sign the request using your wallet. It’s important to note that only the wallet that approved the consumer in the Oracle can sign and upload the headers. Any signatures from other wallets will be rejected by the Oracle.
The process is simple:
- After entering the headers, click on the Sign with Wallet button.
- Your wallet will prompt you to confirm the signature.
- Once signed, the headers will be ready to send the Oracle.
Slots: Managing Multiple Headers for a Consumer
In addition to uploading headers, each consumer has 5 available slots that can be used to store different sets of headers. This feature is crucial for contracts that interact with multiple APIs requiring different headers for each request.
What are Slots?
Slots allow a single consumer contract to manage multiple sets of headers that will be used in different API requests. This enables a consumer contract to send requests to different APIs, each requiring a unique set of headers.
- Each consumer has up to 5 slots where different headers can be stored.
- A slot is specified in the request made from the consumer contract to the Oracle.
- Depending on the value of the
slot
specified in the request, the Oracle will select and include the appropriate set of headers when making the API request.
How to Use Slots On-Chain
When creating an on-chain request from the consumer contract, you can specify which slot the Oracle should use to retrieve the relevant headers. Here's an example of how you can set up a request and select a specific slot:
OracleRequest.Request memory req;
req.url = url; //requiered
req.method = "POST"; //required
req.slot = "0"; // <-- SELECT SLOT YOU WANT TO USE FOR THIS REQUEST
req.jsonResponsePath = "data.result";
req.requestBody = requestBody;
testerCustomBody = req.requestBody;
req.bodyValuesDataTypes = '["uint256","string"]'; // remember double quote in elements of string array for match json format
bytes memory requestData = req.encodeCBOR();
- Upload secrets are optional, if you are making a request to a public API that not require authentifications you dont need to configure any header, so you dont need to pass req.slot
Step 4: Submit the Signed Headers
Finally, after signing the headers, you can submit them to the Oracle. The Oracle will now include these headers in its requests to the target API.
Important Notes
- Only signed headers from the approving wallet will be accepted.
Any headers signed by a wallet that did not approve the consumer will be automatically rejected by the Oracle.