An oracle in blockchain is a trusted data source that sends information to the blockchain for use by other smart contracts. Augur and Gnosis, Ethereum-based platforms, already use oracles to capture stock market data. In general, oracles are an integral part of multi-signature contracts. The Tezos and EOS blockchains are examples of oracle use.
Blockchains cannot collect data from the external environment and share information with it themselves. For example, a smart cryptocurrency exchanger does not know how much a coin is worth in the market and at what price it should be exchanged. It is a lot like a computer that is not connected to the Internet.
A smart contract is hard to write: it takes a lot of time and hard work. Often, information that was relevant when the smart contract was first written becomes irrelevant by the time it is used. Smart contracts need oracles to cover details that cannot be unequivocally known and understood at the time they are written.
As an example, consider the following situation: Alice and Bob bet on what the temperature will be on Saturday. Alice thinks the temperature will be 20°C or higher, and conversely, Bob thinks the temperature will be 19°C or lower (to the nearest whole number). They develop a smart contract (to which they will both send funds) that is paid to the winner depending on the temperature. In order for the smart contract to determine the temperature and thus pay out to the winner, they must request a reliable source or oracle and use the result to begin execution. After querying a local weather news website, the value is the temperature value of 24° C on Saturday. The smart contract is then executed on its terms and sends all funds to Alice. In this situation, the local news site is the oracle.
So if a smart contract needs to know how much a token is worth or what the price of a barrel of oil is, it is the oracle that gives it that data.
Blockchain oracles verify the terms and conditions of smart contracts and provide them with the information they need to execute them. They are not part of the blockchain and therefore do not compromise its security - the network is still decentralized, but it has external data. Connection to external resources is through APIs.
Why do we need blockchain oracles?
The ability to access external data multiplies the functionality of smart contracts and decentralized applications.
For example, the DeFi sector would not be possible without blockchain oracles. Decentralized finance relies on accurate, verifiable data. Lending, derivatives, insurance, and trading all require data on the quotes of various digital assets. For example, blockchain pricing oracles collect data from cryptocurrency exchanges about the price of tokens - so lenders in DeFi-protocols know the size of the collateral.
It is important to understand that oracles are not a source of information, but only a provider of it.
First, oracles collect external data and process (verify) it. This data can be any condition of a smart contract: the value of a coin, the execution of a payment, or the current state of the blockchain network. At this stage, the oracle's task is to correctly select the information and make sure that it is correct. For example, to select the actual rate of a cryptocurrency among dozens of quotes on different trading floors.
Another important function of oracles is to transmit data in the right format, so that different systems (blockchains, decentralized applications, trading platforms, IoT devices, and so on) can communicate with each other. A blockchain network cannot simply communicate with any other system because they often use different programming languages and have different system requirements. But thanks to oracles, different blockchains can be interoperable.
Types of blockchain oracles
There are several basic types of oracles. First of all, blockchain oracles are divided by data sources:
Software-based - they collect data from Internet sources, such as websites, in real time. Most often, such oracles collect information about quotes and exchange rates of cryptocurrencies;
Hardware - collect data from the environment, for example, using motion sensors or barcodes. Such oracles can be used in the Internet of Things (IoT), for example, to confirm that an ordered shipment is in place;
Consensus - collect information from prediction marketplace protocols such as Augur or Gnosis.
According to the direction of information transfer, oracles are divided into:
Incoming - provides data to the smart contracts from the outside world;
Outgoing - transmits information from the smart contracts to the outside world. For example, a smart contract can be programmed to unlock the smart lock in an Airbnb apartment - it will open if the owner confirms receipt of the rent payment.
What's more, oracles are divided by the degree of centralization:
Centralized - use only one data source and are controlled by a single center;
Decentralized - request data from multiple sources and compare them.
Usually the oracle falls into several categories at once. For example, Chainkink is an oracle that reports data on cryptocurrency quotes to protocols and is also decentralized, inbound and software.