What are Oracles? (Simplified Explanation)
Oracles are data messengers that feed external data into smart contracts, enabling the smart contract to make up-to-date decisions, in real-time. They essentially act as a bridge between the real and digital world, via fetching data from the outside world and feeding into the digital world (smart contracts.
For example: a decentralised application (dApp) that automatically pays out insurance claims based on the weather. Let’s say this dApp will pay out £100 to everyone who claimed that it would rain at 2:00 pm in Manchester. The dApp would need to know at 2:00 pm if it rained in Manchester. How would this virtual dApp, be aware of the real-life weather? Through an Oracle.
The Oracle would check the real-world weather, feed that data into the smart contract on the dApp, and the smart contract would automatically execute the insurance policy. Let’s say it did rain at 2:00 pm in Manchester. The process would be as follows:
- Oracle picks up it is raining at 2:00 pm in Manchester
- Oracle relays information to smart contracts on dApp
- Smart contract in real-time would automatically pay out £100 to all insurance claimants who claimed it would rain in Manchester at 2:00 pm.
It is important to understand a smart contract is a piece of code that automatically executes agreements based on certain criteria. Smart contracts CANNOT access or verify data on the outside world, hence why Oracles are required.
What are Oracles? (Advanced)
A decentralised finance (DeFi) platform offers a smart contract for automated trading based on specific stock market conditions. For example, a user wishes to buy 100 shares of Company XYZ if its stock price falls below $50.
How it works:
- Smart Contract Setup: user sets up a smart contract on the blockchain with the condition (rule) for purchasing 100 shares of Company XYZ if the stock price falls below $50.
- Oracle’s Role: the blockchain cannot directly access the stock market data, so it relies on an oracle to monitor Company XYZ’s stock price.
- Data Fetching: oracle is programmed to regularly check stock price of Company XYZ from reliable financial data sources such as stock market feeds or financial news APIs.
- Verification and Submission: oracle fetches the current stock price, verifies data for accuracy by comparing multiple sources to ensure reliability and then submits this information to the blockchain.
- Condition Evaluation and Execution: oracle submits data indicating Company XYZ’s stock price has fallen below $50, and the smart contract automatically executes a buy order for 100 shares on behalf of the user.
Types of Oracles
Oracles can be categorised based on various criteria including a source of data, the direction of data flow, the degree of decentralisation, and the nature of the information they provide.
Source of Data
- Software Oracles: handle data on the internet. e.g. temperature, prices of commodities, and currencies.
- Hardware Oracles: fetch data from PHYSICAL WORLD, typically using devices such as barcode scanners and electronic sensors. Hardware oracles then translate that information into code that can be understood by smart contracts. For example, RFID sensors allow goods to be tracked along supply chains.
Direction of Data Flow
- Inbound Oracles: take information from an external source and send it a smart contract. Example: Oracle checking Ethereum price and sending it a DeFi smart contract.
- Outbound Oracles: send data from smart contracts to the external world. Example: a smart contract that sends you a notification on your phone whenever you receive deposits in your bitcoin wallet.
Nature of Information
- Consensus Oracles: gather data from MULTIPLE sources to reach a consensus (agreement). Helps reduce anomalies and inaccuracies from any single source
- Computation Oracles: perform computations outside the blockchain. Example: calculates user credit score for a dApp that offers personal loans.
Degree of Decentralisation
- Centralised Oracles: single source provides data.
- Decentralised Oracles: source information from multiple sources. They combine multiple independent Oracle node operators and multiple reliable data sources to establish end-to-end decentralisation. Such oracles leverage hybrid smart contracts.
Hybrid smart contracts: an application that consists of a smart contract that runs on a blockchain and off-chain services that support the smart contract (oracles).
- Human Oracles: humans provide information or make decisions that are fed into the blockchain. They tend to be experts in a particular field.