What is a blockchain oracle?
A blockchain OracleAn oracle is a service that brings outside information, such as a market price, onto the blockchain for contracts to use.See it in the glossaryRead the explainer is a service that delivers real-world information, such as a price, to a blockchain. A Smart contractA smart contract is a program stored at an address on the blockchain that anyone can call and that runs exactly as written.See it in the glossaryRead the explainer knows its own code, its own storage and the state of the chain. It knows nothing about the weather, a football score or the price of gold. An oracle closes that gap.
A contract cannot fetch outside data itself because every node must replay every transaction and reach the identical result. A web request could return different answers to different nodes, and the nodes would then disagree about what happened.
So the data is written to the chain first, as an ordinary transaction. After that, every node reads the same stored value. An oracle is the party that writes it. Someone has to collect the fact, sign it and publish it, and the quality of that process decides whether you can trust the number.
What is a price feed?
A price feed is a contract with a fixed address that stores the latest price of one asset pair, such as ETH/USD. It also stores the time of the last update. Each pair has its own feed. Other contracts and apps read from it like from any contract.
A feed works like a noticeboard in a shop window. Anyone can read the day’s price, and the board does not decide it. It shows what its sources reported.
Contracts that lend, trade or mint against a price read feeds in this way. The health factor in Aave depends on a price oracle. A feed answers two questions: what is the latest price, and when was it set. The staleness guide covers the second in depth.
A feed stores its price as a whole number, so you divide by the feed’s decimals to get the real price. A feed with 8 decimals stores the made-up price 2,000.50 as 200050000000. The same rule applies to token DecimalsDecimals tell you how many digits of a token amount sit after the decimal point, because contracts store whole numbers only.See it in the glossaryRead the explainer, which What is ERC-20? explains. Many USD feeds use 8, but some feeds, such as those that price an asset in ETH, use 18. Read decimals() from the feed you use.
How Chainlink collects a price
Chainlink is a decentralized oracle network. Several independent operators each report a price, and the feed publishes the middle value, called the median, instead of trusting one source.
Each operator gathers prices from data providers and reports its own number. If one reporter is wrong or malicious, its number lands at the edge and is ignored.
A single source is a single point of failure, and a group with a median is harder to bend. Chainlink is not the only option. Other networks exist, and some protocols build their own price source. The idea is the same: several inputs, one agreed output, stored where contracts can read it.
Push and pull: how fresh is the price?
A push oracle writes the price to the chain on its own. A pull oracle waits until you ask and delivers a fresh price inside your transaction.
Chainlink’s classic price feeds are push feeds. A new price is written when the price moves by a set percentage, or when a set time passes with no update. That time limit is the heartbeat. Between updates, the stored price can trail the real market.
With a pull oracle you fetch a signed price off-chain and pass it into your transaction. The contract checks the signature and uses the price. Chainlink Data Streams and Pyth work this way.
Neither is better in general. Push is simple to use because the price is already on the chain. Pull can be fresher, but your app must fetch and send the price each time.
What can go wrong with oracles
An oracle is a trust point, so the main risks are a stale price, a wrong price and a manipulated price. A contract that treats the oracle as perfect inherits all three.
-
Stale price. The feed stopped updating, or the network around it was down. The contract keeps using an old number. Checking the update time catches this.
-
Wrong or thin source. A price taken from one small market can be pushed around cheaply. Aggregating many sources makes that much harder.
-
Wrong feed. A contract points at the wrong address or the wrong pair and reads a valid price for the wrong thing.
On a Layer 2A layer 2 is a separate chain built on top of Ethereum that processes transactions more cheaply while relying on Ethereum for security.See it in the glossaryRead the explainer chain such as Base, the operator that orders transactions can go offline. Chainlink publishes a separate sequencer status feed for this, covered in the correct-usage guide. Reading a price correctly takes a few checks beyond a function call.
See it on a real contract
The card reads the Chainlink ETH/USD feed on Ethereum, the price much of onchain finance relies on. Open the Chainlink Price Feed Reader to see the pair name, the decimals and the same feed’s price, or pick another pair to compare feeds.
ETH price in US dollars, from the Chainlink ETH/USD feed
Reading live from Ethereum
Open this feed in the Chainlink price feed reader
Show the query
formatUnits(feed.latestRoundData().answer, feed.decimals())Common mix-ups
-
“The oracle is the source of the price.” It is not. The oracle collects prices from markets and data providers and publishes the result onchain. The markets set the price.
-
“Onchain prices are always live.” They are not. A push feed updates on a price move or a heartbeat, so the stored price can trail the market.
-
“A price feed returns a decimal number.” It returns a whole number. You divide it by
decimalsto get the price. -
“Oracles and Chainlink mean the same thing.” Chainlink is one oracle network. It is the most widely used for price feeds, but not the only one.
Summary
- A blockchain oracle publishes outside data, such as a price, onto the chain, because a smart contract cannot fetch it on its own.
- A price feed is a contract that stores the latest price of one asset pair and the time it was set. Chainlink publishes the median of several independent reports.
- Onchain prices can be stale, so check the update time and divide the stored whole number by the feed’s decimals.
For developers
One evmquery expression can read a feed’s pair name, price and update time, and you should compare the update time with the current time before acting on a price. The staleness, sequencer and decimals guide shows the full checks.