Chapter 1 of 9

Why an oracle

Goal. Understand why a smart contract cannot read the internet and how an oracle solves the problem.

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.

Analogy. Think of a notary who only trusts what you bring to the desk. They do not go out to check prices: if you want them taken into account, someone must bring a sheet, and the notary files it with the date. The sheet is the data; whoever brings it is the oracle.

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

Going deeper