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.
The shortcut
For any contract that uses outside data, ask "who could lie?" List every party whose report can move the money, and check that no single one of them can do it alone.
The new rule
releasecan now also be triggered by an oracle report that the parcel was delivered.
The trap is trusting a decentralized contract that relies on one centralized oracle. It is only as trustworthy as that single oracle.
Drills
Answer fast — trust the rule.
Why can't the escrow contract just call the courier's website itself?
Five oracle nodes report a price: 101, 102, 100, 250 and 101. What is the median?
In that example, what would happen if the network used the average instead of the median?
A lending contract uses one company's server as its only price oracle. What is the biggest risk?
Remember
- A contract is only as trustworthy as the oracle that feeds it.
- Shortcut: ask "who could lie?" No single reporter, and no single source, should be able to move the money.
- Trap: many oracle nodes reading one source still share that source's errors, and the median resists outliers where the average does not.
