10

What components do I need to implement an oracle for a Substrate chain, such as a price feed? I'm looking to understand the general steps and considerations I should make. What libraries or projects already exists that I could use?

2 Answers 2

3

There is an implementation of a price feed pallet in the Chainlink-Substrate integration. It connects to and uses the Chainlink oracle network to fetch the price feed.

You can follow a similar approach to build an oracle pallet to connect to any service or oracle for getting data in the chain. Here is the code - https://github.com/smartcontractkit/chainlink-polkadot

Also, here is a good tutorial that explains the process - https://github.com/LaurentTrk/chainlink-substrate-tutorial

This could be a bit outdated considering the evolving code. But the overall approach still makes sense.

Also, as an alternative, you can look at Substrate off-chain workers for getting data via http calls. Here is a good overview - https://docs.substrate.io/v3/concepts/off-chain-features/

These are just some examples, and could be useful in understanding how to approach building your own price-feed or any other oracle integration.

2
  • I believe Sacha is asking how to build a feed oracle rather than how to connect to Chainlink
    – h4x3rotab
    Mar 23, 2022 at 6:53
  • As I said in my answer, "You can follow a similar approach to build an oracle". The chainlink implementation is shared as a reference.
    – Gautam D
    Mar 23, 2022 at 10:51
3
  • orml-oracle pallet template from the Open Runtime Module Library (ORML), which is a community maintained collection of Substrate runtime modules, shows the foundations of how to create an oracle to make off-chain data available on-chain using off-chain workers.

  • substrate-price-oracle by Shawn Tabrizi shows specifically how to create an oracle that fetches off-chain price data and stores it on-chain using offchain workers.

  • pallet-chainlink-feed by Chainlink is a more complex example of how to create an oracle that fetches off-chain price data and interacts with a seperate token pallet for separation of concerns.

  • example-offchain-worker pallet and numerous online tutorials with Tomasz DrwiÄ™ga show how to use an oracle to fetch data from an external API using off-chain workers and store it on-chain.

Not the answer you're looking for? Browse other questions tagged or ask your own question.