What Is a Blockchain Oracle?
By: Patrick Collins
Tags: Solidity, Ethereum, Cryptocurrency, Programming, Blockchain

1. What Is an Oracle?

A blockchain oracle is any device or entity that connects a deterministic blockchain with off-chain data.

There is a lot to unpack in that one sentence.

To understand what blockchain oracles are and why we need them, let’s go back to one of the core features of a blockchain — decentrality.

The problem with blockchains

Since the blockchain has its distributed ledger nature, each node in the network has to be able to find the same end result given the same input. Otherwise, when a node looks to validate a transaction another node makes, it would end up with a different result. This architecture is intentional, and it’s designed to be deterministic intentionally.

New balance is easy to get (Image source: Author)

We can see when we send $5 from Bob to Alice, we can easily add $5 to Alice’s balance and subtract $5 from Bob’s. Every node on the network could easily reproduce this, get the same results, and end up in the same state.

But what if this wasn’t the case? Let’s imagine an imaginary blockchain where they use APIs to validate each other's transactions. Let’s say we want to send a variable amount based on the price of ETH to Alice from Bob’s account. We would have our contract call an API to get the price of ETH and then send that amount to Bob. When every other node goes to verify this, they also have to call this API.

It’s much harder to validate variables. (Image source: Author)

But what happens now? If they call the API even an instant later, the API could have changed — been depreciated, hacked, or for a number of other reasons — and all the nodes would get a different result. This means none of the nodes would be able to agree upon what the actual state of the blockchain is.

It’s for this reason the Ethereum blockchain and most blockchains are designed to be entirely deterministic. That means if we were to replay every transaction, we would end up in the correct state. If you include API calls or other non-deterministic sources into the infrastructure of blockchain, there is a good chance that the source will be depreciated, hacked, or even just broken, and we would not be able to validate transactions.

Consensus is not possible if blockchain is non-deterministic (Image source: Chainlink)

In blockchain, the mechanism for agreeing upon a data value is called consensus, and determinism is important so that nodes can come to a consensus. You might have heard of some of them, like Proof of Work (PoW) with Nakamoto Consensus or Proof of Stake (PoS) with Byzantine Consensus. Consensus is one of the key ingredients that make blockchain work in the first place.

But we need the blockchain world to connect with the real world. We need to get the price of ETH and other cryptocurrencies into a contract so we can have DeFi. We need to get the weather data so we can have decentralized trustless insurance. We need data to use blockchain for one of its most important purposes, smart contracts. So how do we bridge the worlds with this constraint?

How oracles solve this

A blockchain oracle is any device or entity that connects a deterministic blockchain with off-chain data. These oracles enter every data input through an external transaction. This way, we can be sure that the blockchain itself contains all of the information required to verify itself. This is why oracles are known as blockchain middleware: They are the bridge between the two worlds.

So that’s it, this is great! But what’s this I keep hearing about an “oracle problem”?