Blockchain Oracle: How Smart Contracts Talk to the World

A blockchain oracle conveys information to and from smart contracts to enable them to perform their self-executing functions.

after reading this, you'll understand:

  • A blockchain oracle allows a smart contract to interact with other entities so it can carry out the terms of the contract.

  • The oracle problem describes the concerns that arise from having a decentralized platform rely on a centralized source of data.

  • Many different types of oracles have been developed to handle the communication needs of smart contracts and decentralized finance.

after reading this, you'll understand:

  • A blockchain oracle allows a smart contract to interact with other entities so it can carry out the terms of the contract.

  • The oracle problem describes the concerns that arise from having a decentralized platform rely on a centralized source of data.

  • Many different types of oracles have been developed to handle the communication needs of smart contracts and decentralized finance.

Blockchain oracles are an essential component of decentralized finance. Although smart contracts are self-executing, they typically need information from the outside world. Blockchain oracles supply that information.

As computer code living on the blockchain, smart contracts are designed to be immutable. Once they go live, the terms of the contract, which is the same as saying the coding of the contract, cannot be changed. That makes sense. If you signed a contract to buy a car, you wouldn't want the dealership calling in a week to say that they updated the contract and the car now costs $10,000 more. The terms of a smart contract must be immutable for the contract to have any meaning.

Smart contracts also are self-executing. Once certain conditions have been met, they trigger the next step in the contract. It's often returned to as "If ... then" logic. But how does the smart contract know if conditions have been met? An oracle tells it. And how does the smart contract tell another party to, for example, send payment to a contract holder. It uses an oracle. 

Let’s take the example of a smart contract used for betting on soccer. Without access to a real-time data source for soccer scores, this smart contract cannot function. Furthermore, if the smart contract receives incorrect data, the wrong people might receive payouts. Because the blockchain is immutable, those incorrect payouts could not be reversed.

What is a blockchain oracle?

"Blockchain oracle" is really just a method of feeding information into a smart contract. (The term "oracle" has its roots in ancient Greece, where certain individuals, usually women, were given that title. They were believed to have the power to channel messages from the gods to mortals.) Now, oracles channel messages from data sources to smart contracts. Smart contract developers leverage oracles (and off-chain data) to bring a contract to life with real-world data.

However, an oracle must be a trusted data source. Oracles sometimes need to reconcile different sources of information and feed them into a smart contract. With only one chance to get things right on the immutable blockchain, users must have confidence in the reliability of the data.

Let’s go back to our example of a smart contract for betting on soccer. An application programming interface, or API, is software that enables one computer or program to communicate with another computer or program. Sound familiar? Dozens of APIs might be used to supply soccer scores for different applications. An oracle, which itself is an API, would take these data feeds and compare the scores from each source. That oracle-API calls the smart contract to give it the correct score so the right bettors can be paid off.

The oracle problem

The blockchain agrees upon data values through consensus. Determinism enables individual nodes to reach a consensus. A blockchain oracle can connect a deterministic blockchain with off-chain data. In other words, an off-chain oracle will gather information and report it on-chain for blockchain transactions. This is why oracles are often referred to as middleware.

However, there is something called the oracle problem. The whole point of smart contracts and decentralized finance is that they are decentralized. They don't require third parties to get in the way, exert undue influence and inflate costs. But the use of oracles – centralized oracles – are a point of failure. A centralized data source has control of the contract’s execution.

However, solutions like Chainlink can prevent oracles from nullifying the advantages of decentralization while addressing the security risks associated with external data. Chainlink has become the standard for decentralized oracles. It is an open-source effort to provide tamper-proof inputs and outputs to support smart contracts.

How are oracles used in smart contracts?

By looking at the most common types of oracles, we can better understand how they work with smart contracts.

Hardware oracles

Hardware oracles are physical sensors with API capability. For example, if you have hurricane insurance on a smart contract, physical sensors could measure wind speed. If the speed hits a certain limit, the hardware oracle notifies the smart contract. The smart contract executes the terms and notifies another oracle to send the policyholder a check.

Software oracles

Software oracles are used widely in smart contract applications. These collect data from third-party sources, including public APIs. For example, for flight delay insurance, the data source could feed information on flight status to the smart contract. If the policyholder’s flight is delayed, the computer code on the smart contract will execute a compensation transaction.

Consensus oracles

Consensus oracles use aggregated data from various oracles with proprietary methods to verify their accuracy and legitimacy. These act as decentralized oracles, or at least represent a move toward decentralization through consensus. They compile and analyze multiple data sources to reach one data point.

Cross-Chain Oracles

Cross-chain oracles allow for interoperability between data and assets moving between blockchains. For instance, you could use data on one blockchain to trigger a specific action on another blockchain. Also, cross-chain oracles allow you to bridge assets for use outside their native blockchain.

Inbound Oracles

Inbound oracles transmit data from external sources to smart contracts. These work when a smart contract needs external data – like weather data, supply chain tracking, and other reports of real-world events – to trigger the correct response.

Outbound Oracles

Outbound oracles allow smart contracts to send information to off-chain sources. For instance, if funds need to be deposited to an address, a smart contract could send data through an outbound oracle to a mechanism that will make it happen.

Computation Oracles

Oracle computation uses decentralized oracle networks (otherwise known as DONs) to execute off-chain computation for smart contracts. It is much less expensive to crunch data off the blockchain. So, computation oracles increase the scalability of smart contracts because they are very cost effective. This type of oracle can help to create trust-minimization guarantees as they remain anchored to blockchains.

Common oracle set-ups

The three main ways to set up an oracle are usually categorized as immediate-read, publish-subscribe, and request-response.

  • Immediate-read oracles provide data that is usually desirable for a fast, prompt decision. This type of information is often required on a last-minute, just-in-time basis.

  • Publish-subscribe oracles offer a broadcast service for information that may frequently vary. Much like an RSS feed, the oracle updates with new information and “flag signals” indicating new information is available to those who are “subscribed.”

  • Request-response oracles are used for all-encompassing and expansive datasets that are too large to store on a smart contract. These are often used when only a small part of the overall dataset is used at any given time.

Conclusion

With more resources than ever before, it’s never been a better time to consider the possibilities of smart contracts. On Hedera, you can build decentralized applications and protocols that scale with EVM smart contracts. Learn more about our smart contract service and get started building your decentralized application.