Tutorial: Create a Custom Oracle In Less Than 5 Mins Using The Oracle Factory

📺 Watch the video version of this tutorial here ⏯

The iExec Oracle Factory is a developer interface allowing anyone to create their own oracles from scratch, in just a few minutes. No specialized blockchain or coding knowledge is needed and users can create oracles directly from their browser. This tutorial will walk you through this process.

If you haven’t already, check out the announcement blog post and learn more about the Oracle Factory.

Preparation:

Navigate to https://oracle-factory.iex.ec/builder and then log in with the appropriate wallet.

           
  • Verify that you are on the right network. You should select “iExec Test Sidechain”
  •        
  • Click “sign”.
  •        
  • Now you’re ready to create your oracle!

Phase 1: Choose Your Workflow

Tips:

           
  • Choose a workflow that suits your needs and technical level.
  •        
  • Preset Data is a demo using preset APIs provided by iExec, it will show you the steps of creating an oracle. It’s for those who just want to get a basic idea of the Oracle factory. No technical or blockchain knowledge is needed for this workflow.
  •        
  • Propose a New API: create a custom oracle with your JSON API. Use this process to create a one-of-a-kind oracle, from NFT prices to polo game results. Users will need to know how to analyze JSON and some basics about the Web to utilize this pathway.
  •        
  • Click “I’ll propose a new API”, then “Next”.

Phase 2: Configure the Oracle

Tips:

           
  • It is important to have an API “compliant”. The beta version of the Oracle Factory accepts two types of APIs:
  •        
  • A public unauthenticated API (no API key)
  •        
  • The API requires someone to sign-up, then distribute an API key, further calls will be made on the name of the signee. It avoids other people to act on his name (which can lead to violation of the API rules, API key revocation and/or account ban).
  •        
  • Why use an API with an API key? An API key protects against other Dapps or malicious hackers accessing your API without your permission.
  •        
  • Visible in Public vs. private: You can choose if you want to make the oracle visible to all in the gallery (public), or just keep it to yourself (private). If you have chosen “Public”, an iExec admin has to allow it to appear.

Phase 3: Configure the API

This phase requires knowledge in JSON analysis. Here are two examples of a JSON analysis.

Let’s start by building an oracle that pulls the gas price from Defipulse. If you’d like another example, see our Appendix on how to create an oracle for slippage data from the market data provider Kaiko.

DeFi Pulse is a site where you can find the various analytics and info for DeFi protocols. The API used here is an API for Defipulse’s demo purchase, with a cap on the daily number of calls.

Example API: https://data-api.defipulse.com/api/v1/egs/api/ethgasAPI.JSON?api-key=5adb999ee2629fc8b7bf1ef11e35bda8a9071949060e557a756c37593e43

If you want to create a pricing oracle using Defipulse data:

           
  1. Paste your API in the section marked ②
  2.        
  3. Find the API-key in your API. Tip: this is the sequence that comes after api-key= See our screenshot above if you need help. It’s the highlighted part in the section called API URL (we marked it ②).
  4.        
  5. Copy the API-key. Paste it into the section called API Key. See our screenshot above if you need help. We marked it as ②. Expected result:

4. Then input “%API_KEY%” manually where you cut the API key in ②. Expected result:

This step allows you to replace your API key with %API_KEY%, so that you don’t need to reveal your key to malicious hackers.

5. For the Header & JSON path part, you will have to do a JSON analysis. Open an internet navigator. Input the API and obtain the below result.

6. Go to a JSON path finder such as: https://jsonpathfinder.com/ .

Paste all to analyze your API.

7. Choose one “Path” that interests you from the returned results. Remember that the Oracle Factory Beta can only return one point of data at a time. In the example above, average is chosen. Copy only the name of the Path you wish to use.

8. Go back to the Orale Factory , respect the “$.xx” format and input $.average

9. Choose the type of value returned (number, Boolean, string).

All right! Now let’s have a final look at what we’ve input so far. 🔥🔥

11. Click Test API.

If there is no error, click Next. If there is an error, you’ll have to debug to find out why.

Hooray! So far you’ve finished the biggest part of the work.

Phase 4: Review the Smart Contract

           
  1. Click Create.

2. Wait for your oracle to be created.

3. View your oracle in your gallery. Your gallery is where you can manage or trigger your oracle to update the value. It can be found at https://oracle-factory.iex.ec/gallery

4. Click on Update to get the latest value.

One more thing:

If you’re curious, you can make a request to update your oracle, the ongoing transaction can be found in the explorer 🔎 ➡️https://explorer.iex.ec/viviani

explorer iexec oracle factory

Congratulations! Now you know everything about the iExec Oracle Factory!

Now, you may be interested in knowing how to integrate your newly created oracle into your Dapp: check out the tutorial!

Tutorial: Integrate an Oracle From the Oracle Factory into your Dapp

APPENDIX

Kaiko is a leading market data provider, offering real-time and historical cryptocurrency trade data, order books, and aggregated prices through a cryptocurrency API.

For the creation of the oracle of slippage data, the format of API and the key is a little bit different: the key is given separately, so no need to seek the key in API URL, replace it with %API_KEY%. but to input it in the header.

Thanks for reading, and happy oracle creating!

Twitter •Youtube •iExec Roadmap •Github •Telegram •Slack