# How to use Oracle

## Pre-requirements

1. [Subkey tool](https://www.substrate.io/kb/integrate/subkey) to create substrate account&#x20;
2. [Polkadot.js](https://polkadot.js.org/) "apps wallet" to connect to nodes

## How to become an oracle

1. If you don't have substrate account yet you can generate it using subkey tool.&#x20;
   1. Use this command: `subkey generate --scheme Sr25519` to generate account with Sr25519 scheme.
   2. Successful result will look like on a picture, but with different values.

![](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPWzIsyMaw22AJxEiX%2FSnipaste_2021-04-15_18-19-33.png?alt=media\&token=d6407a25-1ecb-471e-968e-fa608742b8d7)

2\.  Insert account key in keystore via polkadot.js

1. Use `Developer`  and `RPC calls`. Endpoint `author` and `insertKey`.
2. `KeyType` is “orac“, `suri` is secret phrase from substrate account and `publicKey` is public key from substrate account.
3. Appearance of the request with the result of execution can be seen on a picture
4. To check that execution was successful you can call `hasKey`, providing your account public key and `keyType` = "orac"

![Point 2.3. Successfully inserted key](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MZD5UX8Y6I2oHOu84jv%2F-MZD70X5i2GwYpL5Ek0D%2FSnipaste_2021-04-26_15-20-36.png?alt=media\&token=d514c0aa-f0d7-4a58-81cd-48d120e09cb9)

![Point 2.4. Check that key was successfully added](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPdIrOCbxLq0ZOOud_%2FSnipaste_2021-04-16_15-20-52.png?alt=media\&token=87e273fc-a850-41c3-b423-cb801fb3bfde)

3\. Add account to white list in polkadot.js

1. Ask Equilibrium team to add your account to whitelist.
2. To check that execution was successful you can call `Developer` and `Chain state`, query `whitelists` and `whiteList`, providing substrate account id or SS58 Address.

![Point 3.2. Check that account was whitelisted successfully](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPfqFEozChogwOJHL1%2FSnipaste_2021-04-16_12-22-00.png?alt=media\&token=3ec91023-f975-4980-be87-9b9390480b96)

4\. Choose resource type and add resource type to off-chain local storage.

1. Available resource types are:
   * “cryptocompare“ in hex representation (0x63727970746f636f6d70617265) for cryptocompare with api key as source.
   * “custom“ in hex representation (0x637573746f6d) for custom source.
2. To add resource type to off-chain local storage use `Developer`  and `RPC calls`. Endpoint `offchain` and `localStorageSet`. Kind is `PERSISTENT`, key is `“oracle::resource_type“` in hex representation

   (0x6f7261636c653a3a7265736f757263655f74797065). Value is your choosed resource type.
3. To check that execution was successful you can call endpoint `offchain` and `localStorageGet`. Kind is `PERSISTENT`, key is `“oracle::resource_type“`  in hex representation

   (0x6f7261636c653a3a7265736f757263655f74797065). The result is your choosed resource type.

![Point 4.2. Successfully added "custom" resource type.](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPllJ4MdhP0PX23Q2-%2FSnipaste_2021-04-16_12-52-38.png?alt=media\&token=b0be1eec-dd53-42ba-be9e-c95a639ec98a)

![Point 4.2. Sucessfully added "cryptocompare" resource type.](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPluxhXoNJYroiiEDJ%2FSnipaste_2021-04-16_12-52-59.png?alt=media\&token=ae26c32c-9c96-4a99-9414-d316e9e4e234)

![Point 4.3. Check that resource type was successfully added for "cryptocompare".](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPoNNCtMNjQs-IR_my%2FSnipaste_2021-04-16_16-13-52.png?alt=media\&token=4e541200-0054-4bee-bd9f-83df729cf82a)

## Configure resource

**Important note:** You can add only one resource.

### Cryptocompare

For cryptocompare resource type you will need to add cryptocompare api key to off-chain local storage.&#x20;

1. Use `Developer`  and `RPC calls`. Endpoint `offchain` and `localStorageSet`. Kind is `PERSISTENT`, key is `“oracle::cryptocompare_api_key“` in hex representation (0x6f7261636c653a3a63727970746f636f6d706172655f6170695f6b6579) and value is `cryptocompare_api_key` in hex representation.
2. To check that execution was successful you can call endpoint `offchain` and `localStorageGet`. Kind is `PERSISTENT`, key is `“oracle::cryptocompare_api_key“` in hex representation (0x6f7261636c653a3a63727970746f636f6d706172655f6170695f6b6579). The result is your cryptocompare api key in hex representation.

![Point 1. Add cryptocompare api key](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPtNFuHfc__CtglWVh%2FInkedSnipaste_2021-04-16_13-01-59_LI_Moment.jpg?alt=media\&token=c0328c4e-18e1-407c-b094-f9a1ec10fbf3)

![Point 2. Check that cryptocompare api key was successfully added](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPvTRUs7rAGVgUsieq%2FSnipaste_2021-04-16_16-41-11.png?alt=media\&token=fe33f13b-3123-447a-9d91-ff22e9f05ad1)

### Custom type

For custom type you will need to add query to off-chain local storage, key is `“oracle::custom_query”` in hex representation (0x6f7261636c653a3a637573746f6d5f7175657279). Value&#x20;

1. Use `Developer`  and `RPC calls`. Endpoint `offchain` and `localStorageSet`. Kind is `PERSISTENT`, key is `“oracle::custom_query”` in hex representation (0x6f7261636c653a3a637573746f6d5f7175657279) and value is query in hex representation.
2. To check that execution was successful you can call endpoint `offchain` and `localStorageGet`. Kind is `PERSISTENT`, key is `“oracle::custom_query”` in hex representation (0x6f7261636c653a3a637573746f6d5f7175657279). The result is your cryptocompare api key in hex representation.

Here is examples for different sources:

1. **Hitbtc**
   * query:  `json(https://api.hitbtc.com/api/2/public/ticker/{$}USD).last`
   * value: `0x6a736f6e2868747470733a2f2f6170692e6869746274632e636f6d2f6170692f322f7075626c69632f7469636b65722f7b247d555344292e6c617374`
2. **Binance**
   * query:  `json(https://api.binance.com/api/v3/ticker/price?symbol={$}USDT).price`
   * value:  `0x6a736f6e2868747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d7b247d55534454292e7072696365`
3. **GDAX**
   * query:  `json(https://api.pro.coinbase.com/products/{$}-USD/ticker).price`
   * value:  `0x6a736f6e2868747470733a2f2f6170692e70726f2e636f696e626173652e636f6d2f70726f64756374732f7b247d2d5553442f7469636b6572292e7072696365`
4. **Kraken**
   * &#x20;query: `json(https://api.kraken.com/0/public/Ticker?pair={$}USD).result.{$}USD.c[0]`
   * value:  `0x6a736f6e2868747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d7b247d555344292e726573756c742e7b247d5553442e635b305d`
5. **Bitstamp**
   * query:  `json(https://www.bitstamp.net/api/ticker/{$}usd).last`
   * value:  `0x6a736f6e2868747470733a2f2f7777772e6269747374616d702e6e65742f6170692f7469636b65722f7b247d757364292e6c617374`
6. **Bitfinex**
   * query:  `json(https://api-pub.bitfinex.com/v2/ticker/t{$}USD).[6]`
   * value: `0x6a736f6e2868747470733a2f2f6170692d7075622e62697466696e65782e636f6d2f76322f7469636b65722f747b247d555344292e5b365d`
7. **Huobi**
   * query:  `json(https://api.huobi.pro/market/history/trade?symbol={$}usdt&size=1).data[0].data[0].price`
   * value:  `0x6a736f6e2868747470733a2f2f6170692e68756f62692e70726f2f6d61726b65742f686973746f72792f74726164653f73796d626f6c3d7b247d757364742673697a653d31292e646174615b305d2e646174615b305d2e7072696365`

Here is screenshots for Hitbtc source. Similar to any other.

![Point 1. Add query](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYQ0zTTLwjdPvqisk-i%2FSnipaste_2021-04-16_12-54-48.png?alt=media\&token=5a4bc4ff-ac40-4fa2-a000-0bfbd84392be)

![Point 2. Check that query was successfully added](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYQ0q7TxqPIC2sL5Z_u%2FSnipaste_2021-04-16_17-12-02.png?alt=media\&token=f9c2ca13-9b06-4e58-a778-8af539a00cd1)

## Price periodicity

Add price periodicity setting.

1. Use `Developer`  and `RPC calls`. Endpoint `offchain` and `localStorageSet`. Kind is `PERSISTENT`, key is `“oracle::price_periodicity”` in hex representation (0x6f7261636c653a3a70726963655f706572696f646963697479) and value is bloks amount in hex representation. Minimal value is 1. Example for peridoicity = 2 blocks.
2. To check that execution was successful you can call endpoint `offchain` and `localStorageGet`. Kind is `PERSISTENT`, key is `“oracle::price_periodicity”` in hex representation (0x6f7261636c653a3a70726963655f706572696f646963697479). The result is your price periodicity in blocks.

![Point 1. Add price periodicity setting](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPycN9vJ9LF33ftyxz%2FSnipaste_2021-04-16_13-02-46.png?alt=media\&token=2c03aea1-6ba1-47b2-8e6e-718acafc37e8)

![Point 2. Check that price periodicity was successfully set](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MYP8FWn7bJYGesofErF%2F-MYPzfLwY1VTktfwQM6E%2FSnipaste_2021-04-16_17-03-40.png?alt=media\&token=891935a7-2cc4-4e0b-8630-b9eb2498b2d2)

## Check that oracle is working

Use this utility to convert your account ss58 address to polkadot representation. In "Change Address Prefix (Prefix Lookup)" section you can past your ss58 address and "67" as prefix to get your polkadot address.

{% embed url="<https://www.shawntabrizi.com/substrate-js-utilities/>" %}

Here is how it looks like. You can see on a screenshot for point 3.2. in "how to become an oracle" that the same address is displayed there.

![](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MZHTyrbd7j9XPZMy03J%2F-MZIEJF5yl0C5owCwaN_%2FSnipaste_2021-04-27_15-08-58.png?alt=media\&token=f98726d7-8129-4524-9ab1-102b84eb92d8)

To check that your account is working as an oracle and updating prices you can call `Developer` and `Chain state`, query `oracle`and `pricePoints` for any currency. In `data_points` array there should be instance with your account address.

![](https://399939398-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MK_3P6RnPHvv_Gsa_wJ%2F-MZHTyrbd7j9XPZMy03J%2F-MZIEQhfxfZfvV97XF-K%2FSnipaste_2021-04-27_14-56-44.png?alt=media\&token=a9fc26ba-264c-4273-ba09-930c1560a820)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.equilibrium.io/resources/how-to-use-oracle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
