Book a free call

What Is a Blockchain Oracle, and How Does It Work?

A blockchain oracle feeds off-chain data, such as prices or weather, to a smart contract. Learn how oracles work, the main types and the risks to check first.

Hertiv engineering teamReviewed by a senior engineer
6 min read
What Is a Blockchain Oracle, and How Does It Work?
On this page

Short answer

A blockchain oracle is a service that brings data from outside a blockchain, such as asset prices, weather readings or sports results, into a smart contract. Blockchains cannot read outside data on their own, so contracts that need real-world facts rely on oracles. The oracle fetches the data, checks it where possible, and delivers it on-chain in a form the contract can read.

What is a blockchain oracle?

A blockchain oracle is a service that delivers data from outside a blockchain to a smart contract. Blockchains are closed systems: they can only read data that is already on-chain, so a contract cannot check a price, a weather reading or a match result on its own. The oracle bridges that gap by fetching the data, checking it where it can, and writing it on-chain in a form the contract can read.

The data an oracle delivers is called off-chain data. Common examples include asset prices for lending and trading, exchange rates for payments, weather readings for crop insurance, flight status for travel cover, and sports results for betting markets. Without an oracle, none of these contracts could react to the real world.

Oracles are not part of the blockchain itself. They run as separate services, and the contract calls them through a defined interface. That separation matters, because the trust you place in the contract now depends on the trust you place in the oracle too. If you are planning a contract that needs outside facts, smart contract development should start with the oracle question, not end with it.

How does a blockchain oracle work?

A blockchain oracle works in four steps: request, fetch, deliver and verify. The contract, or the app that calls it, asks for a specific fact. The oracle fetches it from one or more sources, formats it, and sends a transaction that writes the value on-chain. The contract then reads the value and acts on it.

  1. Request. The contract asks for a fact, such as the current price of an asset or the rainfall in a district.
  2. Fetch. The oracle reads the fact from its sources, which may be an exchange, a weather station or a public feed.
  3. Deliver. The oracle writes the value on-chain in a transaction the contract can read.
  4. Verify. The contract, or the oracle itself, checks the value against rules, such as a range or a second source, before acting on it.

The verify step is where designs differ. Some oracles simply pass the data through. Others combine answers from several sources and take the middle value, which limits the damage if one source is wrong. A few add a dispute window, during which anyone can challenge a wrong answer before the contract uses it.

What types of blockchain oracles are there?

Oracles differ along three lines: which direction the data flows, where it comes from, and how many parties run them. The table below covers the main types and where each fits.

Type What it does Typical use
Inbound Brings outside data onto the chain Prices, weather, scores
Outbound Sends on-chain events to the outside world Opening a smart lock, paying a supplier
Software Reads data from online sources Exchange prices, flight status
Hardware Reads data from physical sensors Temperature, location, meter readings
Centralised One party runs the oracle Simple feeds, low-value contracts
Decentralised Many independent parties report the same fact Lending, trading, insurance
Computation Runs a calculation off-chain and returns the result Credit scores, random numbers

Most production systems combine types. A lending protocol might use a decentralised price oracle for its main feed and a centralised one as a backup. A supply chain contract might use a hardware oracle for sensor readings and a software oracle for shipping status.

What is the oracle problem?

The oracle problem is the gap between a contract that cannot be changed and data that can be wrong. A smart contract executes exactly as written, so if the oracle delivers a wrong price or a false reading, the contract still acts on it. The code is correct and the outcome is wrong.

This matters because the oracle sits outside the blockchain's own security. The chain can prove that the data arrived in a certain transaction, but it cannot prove that the data was true when it was collected. A compromised source, a failed sensor or a manipulated feed all produce the same result: a contract acting on bad facts.

Designs that reduce the risk include using several independent sources, taking the median value, adding a dispute window, and capping how much value a single data point can move. None of these remove the risk entirely, which is why oracle choice is a security decision, not a plumbing detail. Contracts that move large sums usually pair the oracle with cross-chain checks and limits on each action.

How do you choose an oracle for your project?

Choose an oracle by matching its design to what your contract risks. A price feed for a small game can tolerate a simpler setup than a lending protocol holding user funds. Work through the five checks below before you commit.

  1. Data sources. How many independent sources feed the value, and who runs them?
  2. Update speed and cost. How often does the value refresh, and what does each update cost in fees?
  3. Decentralisation. Can one party change the value, or does it need several parties to agree?
  4. Dispute and fallback. Is there a window to challenge a wrong value, and what happens if the oracle stops?
  5. Audit and track record. Has the oracle been reviewed, and how long has it run without a serious failure?

Cost is easy to overlook. Each oracle update is a transaction, so a feed that updates every few seconds costs far more than one that updates on demand. Match the update schedule to how fast your contract actually needs fresh data.

Example (hypothetical): a crop insurance payout

Example (hypothetical): a crop insurance contract covers 500 small farms. If rainfall in a district stays below 20 millimetres for 30 days, each farm receives a payout of $50. The contract cannot measure rain itself, so it relies on a weather oracle.

In a dry month the oracle reports 12 millimetres of rain. The contract checks the value against its rule, 12 is below 20, and pays out. The total payout is 500 farms times $50, which is $25,000. The oracle fee for the month is $200, so the full cost of the payout run is $25,200.

The weak point is the reading itself. If the weather station reports wrongly, 500 farms are paid for a drought that did not happen, or not paid for one that did. That is why the insurer in this example uses two independent weather sources and takes the lower reading only when both agree it is below the threshold.

What are the common mistakes?

The most common mistakes are trusting a single source, ignoring update costs, and treating the oracle as an afterthought.

  • One source for a high-value contract. A single feed is a single point of failure; use several sources and take the median.
  • No fallback when the oracle stops. Decide what the contract does if no fresh data arrives: pause, use the last value, or refuse new actions.
  • Updating too often. Every update costs a fee, so refresh only as fast as the contract needs.
  • Skipping the dispute window. Without a challenge period, a wrong value is final the moment it lands.
  • Testing only with good data. Test with stale, missing and wrong values before real funds are involved.

Start with the data your contract actually needs, pick the simplest oracle that meets the risk, and test it with wrong and stale data before real funds are involved. A short build with a blockchain development partner can surface these risks early.

Key takeaways

  • A blockchain oracle brings off-chain data, such as prices or weather, into a smart contract
  • Oracles work in four steps: request, fetch, deliver and verify
  • Types differ by direction, source and how many parties run them
  • The oracle problem is that a correct contract still acts on wrong data
  • Use several sources, a dispute window and a cap on what one update can move

Frequently asked questions

What is a blockchain oracle in simple terms?

A blockchain oracle is a service that fetches real-world facts, such as an asset price or a rainfall reading, and writes them onto a blockchain so a smart contract can use them. Blockchains cannot read outside data on their own, so any contract that reacts to the real world needs an oracle.

Are oracles part of the blockchain?

No. Oracles run as separate services outside the chain and deliver data through transactions. That separation matters, because the security of your contract now depends on the security of the oracle as well as the security of the chain.

What is the difference between a centralised and a decentralised oracle?

A centralised oracle is run by one party, which makes it simple and cheap but leaves a single point of failure. A decentralised oracle gathers the same fact from many independent parties and combines their answers, which costs more but limits the damage if one party is wrong or compromised.

Can a smart contract work without an oracle?

Yes, if it only needs data that is already on-chain, such as token balances or past transactions. It needs an oracle only when it must react to facts from outside the chain, such as market prices, weather, scores or delivery status.

What happens if an oracle delivers wrong data?

The contract still executes exactly as written, so it acts on the wrong value. That can trigger wrong payouts, wrong liquidations or wrong trades. Designs that reduce the risk include several sources, median values, dispute windows and caps on how much one update can move.

How much does an oracle cost?

Costs vary by design and update frequency, because each update is a transaction with a fee. A feed that updates every few seconds costs far more than one that updates on demand. Ask the oracle provider for its current pricing page and match the update schedule to what your contract needs.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a smart contract that needs real-world data? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Blockchain Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call