I believe smart contracts cannot make network calls, hence cannot call an external API to get data.

I have read that oracles are ways to provide outside data to smart contracts.

I am now confused on how exactly oracles provide these outside data to smart contracts if smart contracts cannot actually make network request to them.

How does this then work? How exactly does smart contract consumes data from oracles?


2 Answers 2


Let's take Chainlink oracle network as an example:

The first service of Chainlink network is Data Feed and you can get the token price from this service. Let's take a look at how Data feed works.

There are 3 roles in the process, an off-chain oracle network that consists of multiple oracle nodes, multiple data providers supposed to provide data, and an on-chain smart contract to receive the data sent by the off-chain oracle network.

The process of price feed is like below in high level(the actual process is more complicated):

  1. Oracle nodes get data from data providers like CEX and other authorities like coinmarketcap and coingecko.
  2. Oracle node broadcast result across the oracle network and the network get the median number of all number(reach consensus) and generate a report.
  3. Off-chain oracle network sends the report to the on-chain smart contract(aggregator contract) deployed by oracle.
  4. Aggregator contract verifies the report to see if it is generated by nodes registered before.
  5. Consumer contract calls the function in the aggregator contract and get the price of the token.

You can check more details about the data feed here.

  • Thanks for this. It is step 3 and step 5 I am puzzled about. I understand one of the things Oracle provides is consistency. This is why smart contracts cannot make the requests themselves because if they do so, then different nodes running the smart contracts might get different results. How is this solved by this process you highlighted? What part of it ensure that all the invocation of the smart contracts to request data from the oracle will all return the same result? Commented Oct 27, 2022 at 10:12
  • If we look at the price of ETH in terms of USD, the oracles can all report slightly different values [1553.60461297, 1553.28, 1552.46 ...]. This response result would not be different based on the blockchain node that receives it. Takes a nondeterministic response (various prices that are received) and turns it into a deterministic one. Based on the input we can compute the median value and that is now always the same result. The requested data is stored in a smart contract as a means of entering the blockchain. More Info: docs.chain.link/docs/architecture-decentralized-model
    – Richard G
    Commented Oct 27, 2022 at 14:57

Oracles are middlemen to get trusted data from off-chain. There are different oracle providers, each has a different mechanism to validate the data is valid.

For example, chainlink is an oracle provider. Chainlink itself is a blockchain and has nodes to get the data. Each node uses its own smart contracts to get data. To run a chainlink node, you have to lock up some funds so if you cheat you will lose your funds.

Once each node gets the data, the chainlink blockchain has an algorithm to detect if the data is reliable. Let's say you need to get the temperature of a location. 10 chainlink nodes provided values between 40F and 43F but 5 of them provided values between 50F and 55F. So chainlink algorithm will discard those 5 nodes, and will use the average of 10 nodes values between 40F and 43F. (It is algorithm more complex and basically what it does.)

If you check the chainling oracle smart contract, function names are getRoundData or latestRoundData indicating that they do not get the data from a single source.

  • Thanks for the answer. But the part I am missing is how the data retrieved from the oracle get's passed back to the smart contracts? Commented Nov 5, 2022 at 6:43
  • You are interacting with chainlink smart contract. Same as you call a function from other smart contract
    – Yilmaz
    Commented Nov 5, 2022 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.