A blockchain oracle is a service that brings data from outside the blockchain, such as prices, exchange rates, weather, sports results or delivery status, into smart contracts. Smart contracts can only read data that is already on their own blockchain; they can't call an API on the internet. An oracle fills that gap by publishing external data on-chain in a way the contract can trust. Without oracles, most DeFi would not work.
How does an oracle work?
- Data collection: independent node operators fetch data from several sources, such as exchanges and data providers.
- Aggregation: the values are combined, for example by taking the median, so one wrong or manipulated source has little effect.
- On-chain publication: the result is written to an oracle contract, either at regular intervals and when the value moves enough (push model) or on request by the user's transaction (pull model).
- Consumption: smart contracts read the latest value, ideally together with a timestamp to check that it is fresh.
Chainlink is the most widely used decentralised oracle network; Pyth, RedStone and others are common too, especially for fast-moving price data.
What are oracles used for?
- Price feeds: lending protocols use them to value collateral and trigger liquidations; derivatives and stablecoins rely on them too.
- Randomness: verifiable random numbers for games, lotteries and NFT distributions.
- Real-world events: insurance payouts based on weather or flight delays, settlement of predictions, delivery confirmations.
- Proof of reserve: showing that tokens are backed by assets held elsewhere.
- Automation and cross-chain: triggering contract functions on a schedule or condition, and passing messages between chains.
The oracle problem and its risks
A smart contract is only as reliable as the data it receives: if the oracle is wrong, the contract executes flawlessly on bad data. Protocols that used a single exchange's spot price as their oracle have been drained with flash-loan price manipulation. Safer designs use decentralised oracle networks or time-weighted average prices, check for stale data, set sanity bounds, and have a fallback or pause when feeds fail. See our DeFi liquidity monitoring, on-chain automation and EVM event listeners.
Frequently Asked Questions about Oracles
Why can't smart contracts call an API directly?
Because every node must get exactly the same result when executing a transaction. An API call could return different answers at different moments, which would break consensus.
What is Chainlink?
A decentralised oracle network whose node operators provide price feeds, randomness, automation and cross-chain messaging to smart contracts on many blockchains.
What is oracle manipulation?
An attack in which someone temporarily moves the price that an oracle reports, for example on a thin trading pool, to borrow too much or trigger unfair liquidations.
Can I run my own oracle?
Yes, for example to publish your own business data on-chain. You then become the trusted party, so it fits best when users already trust you as the data source.