Oracles — Bringing Outside Data On-Chain
The bicycle escrow still has a weak spot: it depends on Asha pressing release. What if the contract could pay Ravi by itself once the courier marks the bike as delivered? The courier's tracking data lives on a website, and a contract cannot read websites. It needs an oracle.
The rule
A contract is only as trustworthy as the oracle that feeds it.
Contracts cannot make web requests, because every node must reach the same result and a website might answer differently from one node to the next, as the first lesson of this section explained. An oracle is a service that fetches off-chain data, such as a price, a rainfall reading, a delivery status or a random number, and posts it to the chain in a transaction, where contracts can read it.
That moves the trust. The contract's code may be flawless, but if the oracle reports "delivered" when the bike never arrived, the contract pays Ravi anyway. This is the oracle problem.
The usual answer is a decentralized oracle network:
- Many independent node operators each fetch the data, ideally from several different sources.
- Their answers are combined, often by taking the median, and the result is signed.
- Operators may lock up collateral and build a public track record, so that lying costs them.
A contract that combines on-chain code with off-chain services like these is sometimes called a hybrid smart contract. Chainlink is one widely used decentralized oracle network; others exist, and the same design questions apply to all of them. Oracles also supply verifiable randomness. A deterministic contract cannot produce unpredictable numbers by itself, and "random" values taken from block data can be nudged by whoever produces the block.