Chapter 1 of 9
Why an oracle
A smart contract is a small program that lives on the blockchain. It follows a golden rule: every computer on the network must get the same result each time it runs. If a contract could ask a website "how much is petrol right now?", two computers asking seconds apart might get two different answers, and the network would no longer agree on anything.
So a contract cannot read the internet. It only knows what is already written on the blockchain.
An oracle is therefore a person or a program that brings a piece of data from the outside world and writes it on the blockchain. From then on any contract can read it, and everyone sees the same number. The delicate point is trust: whoever writes the data decides what the contract "believes". That is why in our project a single authorised address can write, and every write leaves a public trace.
Decentralised oracles also exist, where many independent nodes confirm the data. Here we use a simple, visible oracle, ideal for learning.
Try it
Open the Chainlink documentation page on the topic (link below) and answer in your own words: "why is an oracle needed?". Then write on paper three real-world facts a contract might want to know.
What you learned
- A contract cannot read the internet because the whole network must get the same result.
- An oracle brings outside data onto the blockchain, where everyone reads it identically.
- Whoever writes the data is a point of trust, so it must be limited and visible.