How to use Oracle

Pre-requirements

  1. Subkey tool to create substrate account

  2. Polkadot.js "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.

    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.

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"

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.

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.

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.

  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.

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

  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

    • 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.

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.

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.

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.

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

Last updated