Know the types of oracles and their practical use cases
Oracles, ideally, provide a simple way of getting extrinsic (ie, “real-world” or off-chain) information, like the price of currency pairs, the price of gold, or truly random numbers, onto the Ethereum platform for smart contracts to use.
Blockchains and smart contracts cannot access off-chain data (data that’s outside of the network). However, for several contractual agreements, it’s vital to possess relevant information from the outside world to execute the agreement.
This is where the oracle blockchaines came in, as they provide a link between off-chain and on-chain data. Oracles are essential within the blockchain ecosystem because they broaden the scope in which smart contracts can operate. Without it, smart contracts would’ve very limited use as they would only have access to data from within their networks.
It’s important to know that a blockchain oracle is not the data source itself, but rather the layer that queries, verifies, and authenticates external data sources and then relays that information. The data provided by oracles comes in many forms — price information, the successful completion of a payment, or the temperature measured by a sensor. For example, lets make an API call:
Decentralized oracles share quite the same objectives as public blockchains — avoiding counterparty risk.
They increase the reliability of the information provided to smart contracts without relying on a single source of truth. The smart contract queries multiple oracles to determine the validity and accuracy of the data — this is why decentralized oracles can also be referred to as consensus oracles.
ChainLink has proposed a decentralized oracle network that consists of three key smart contracts — a reputation contract, an order-matching contract, and an aggregation contract — and an off-chain registry of data providers.
A centralized oracle is controlled by one entity and is the sole provider of information for the smart contract. Using one source of information can be risky — the effectiveness of the contract all entirely on the entity controlling the oracle. Any malicious interference from a bad actor will affect directly the smart contract. The main problem with centralized oracles is the existence of a point of failure, which makes the contracts less resilient to vulnerabilities and attacks. If you are willing to trust a centralized but auditable service, you can go to Provable.
Types of Oracles
- Software Oracles: It handles information data that comes from online sources, like temperature, prices of commodities and goods, flight or train delays, etc. The software oracle fetches needed information and pushes it into the smart contract.
- Hardware Oracles: Some smart contracts need information directly from the physical world, for example, movement sensors must detect movement and send the data to a smart contract or RFID sensors in the supply chain industry.
- Inbound Oracles: It provides data from the external world.
- Outbound Oracles: It provides smart contracts the ability to send data to the outside world. For example, a smart lock receives payment on its blockchain address and needs to unlock automatically.
- Consensus-based Oracles: They get their data from human consensus and prediction markets like Augur. Using only one source of information might be risky. To avoid manipulation in the market, prediction markets implement a rating system for oracles. For further security, a combination of several oracles may be used, where, for example, three out of five oracles could determine the outcome of an event.
Practical Use Case
Solidity: To consume price data, your smart contract should reference
AggregatorV3Interfacewhich defines the external functions implemented by Data Feeds.
latestRoundData function returns five values representing the latest price data.