How to use Oracle
Last updated
Last updated
Subkey tool to create substrate account
Polkadot.js "apps wallet" to connect to nodes
If you don't have substrate account yet you can generate it using subkey tool.
Use this command: subkey generate --scheme Sr25519
to generate account with Sr25519 scheme.
Successful result will look like on a picture, but with different values.
2. Insert account key in keystore via polkadot.js
Use Developer
and RPC calls
. Endpoint author
and insertKey
.
KeyType
is “orac“, suri
is secret phrase from substrate account and publicKey
is public key from substrate account.
Appearance of the request with the result of execution can be seen on a picture
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
Ask Equilibrium team to add your account to whitelist.
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.
Available resource types are:
“cryptocompare“ in hex representation (0x63727970746f636f6d70617265) for cryptocompare with api key as source.
“custom“ in hex representation (0x637573746f6d) for custom source.
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.
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.
Important note: You can add only one resource.
For cryptocompare resource type you will need to add cryptocompare api key to off-chain local storage.
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.
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.
For custom type you will need to add query to off-chain local storage, key is “oracle::custom_query”
in hex representation (0x6f7261636c653a3a637573746f6d5f7175657279). Value
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.
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:
Hitbtc
query: json(https://api.hitbtc.com/api/2/public/ticker/{$}USD).last
value: 0x6a736f6e2868747470733a2f2f6170692e6869746274632e636f6d2f6170692f322f7075626c69632f7469636b65722f7b247d555344292e6c617374
Binance
query: json(https://api.binance.com/api/v3/ticker/price?symbol={$}USDT).price
value: 0x6a736f6e2868747470733a2f2f6170692e62696e616e63652e636f6d2f6170692f76332f7469636b65722f70726963653f73796d626f6c3d7b247d55534454292e7072696365
GDAX
query: json(https://api.pro.coinbase.com/products/{$}-USD/ticker).price
value: 0x6a736f6e2868747470733a2f2f6170692e70726f2e636f696e626173652e636f6d2f70726f64756374732f7b247d2d5553442f7469636b6572292e7072696365
Kraken
query: json(https://api.kraken.com/0/public/Ticker?pair={$}USD).result.{$}USD.c[0]
value: 0x6a736f6e2868747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d7b247d555344292e726573756c742e7b247d5553442e635b305d
Bitstamp
query: json(https://www.bitstamp.net/api/ticker/{$}usd).last
value: 0x6a736f6e2868747470733a2f2f7777772e6269747374616d702e6e65742f6170692f7469636b65722f7b247d757364292e6c617374
Bitfinex
query: json(https://api-pub.bitfinex.com/v2/ticker/t{$}USD).[6]
value: 0x6a736f6e2868747470733a2f2f6170692d7075622e62697466696e65782e636f6d2f76322f7469636b65722f747b247d555344292e5b365d
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.
Add price periodicity setting.
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.
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.
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 oracle
and pricePoints
for any currency. In data_points
array there should be instance with your account address.