Where Chainlink Gets Its Data: Guide to How Feeds Work

Published: 6th December, 2023 | Last Updated: 12th March, 2024

Markos Koemtzopoulos

Markos Koemtzopoulos is the founder and main writer of ElementalCrypto. He has been a lecturer at the University of Nicosia on cryptocurrencies and DeFi and has taught two courses on crypto and blockchain technology.

In this post, I will walk you through where Chainlink gets its data from. I will describe how Chainlink connects to external data sources and give you some examples of how their decentralized oracle service actually works. You might also want to check How Does Chainlink Get Its Value.

Heads up: if you don’t know what a smart contract is or are not familiar with the Ethereum network you are going to have a hard time understanding this article. I suggest you read my Crypto 101 tutorials first.

A quick primer on Chainlink

Chainlink is a decentralized oracle network. An oracle is just a fancy word for data feed. You can think of Chainlink as a network of nodes (computers) that feed external data to smart contracts.  

A smart contract is a piece of code that allows you to build an application on top of a blockchain that you can use to set conditions.

It’s kind of like an if..then..statement if you are familiar with coding.

So you can write stuff like: “If the market price of ETH goes below $1,000 then sell the crypto in address xyz.”

However, the problem is that the smart contract does not know the price of ETH because it does not have access to real-world data. To do this it needs to make a data request to a bunch of chainlink nodes and check.

Below is some sample code for a smart contract written in the Solidity programming language. Don’t get scared. You don’t need to be a programmer to see what’s going on here. I just wanted to show you two things.

  • First, it’s cool to see the smart contract in action where it says ” Check if the price is below the threshold “.
  • Second note how, in the third line, the first thing the code does is connect to Chainlink to fetch price data.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract ConditionalSell {

    address public owner;
    address public tokenToSell;  // Address of the ERC-20 token you want to sell
    address public targetAddress; // Address to receive the funds from the sale
    AggregatorV3Interface public priceFeed; // Chainlink ETH/USD price feed

    uint256 public sellThreshold = 1000 * 1e18; // $1,000 in wei

    modifier onlyOwner() {
        require(msg.sender == owner, "Not the owner");
        _;
    }

    constructor(address _tokenToSell, address _targetAddress, address _priceFeedAddress) {
        owner = msg.sender;
        tokenToSell = _tokenToSell;
        targetAddress = _targetAddress;
        priceFeed = AggregatorV3Interface(_priceFeedAddress);
    }

    function setSellThreshold(uint256 _newThreshold) external onlyOwner {
        sellThreshold = _newThreshold;
    }

    function sellIfPriceBelowThreshold() external onlyOwner {
        // Get the latest ETH/USD price from the Chainlink price feed
        (, int256 price, , ,) = priceFeed.latestRoundData();

        require(price > 0, "Invalid price");

        // Check if the price is below the threshold
        if (uint256(price) < sellThreshold) {
            // Sell the ERC-20 tokens
            uint256 tokenBalance = IERC20(tokenToSell).balanceOf(address(this));
            require(tokenBalance > 0, "No tokens to sell");

            // Assuming the ERC-20 token has a transfer function
            IERC20(tokenToSell).transfer(targetAddress, tokenBalance);
        }
    }
}

What kind of data does Chainlink fetch

The most commonly used Chainlink data feeds are prices.

Think of all the decentralized apps around today. None of them have price data available to them inside the blockchain. Even for their native tokens.

Price is something that is determined in the real world.

For example, the price of ETH is not available to the Ethereum blockchain.

Instead, you need to look up the price on a bunch of cryptocurrency exchanges.

Smart contract developers connect to external sources provided by Chainlink to be able to trigger various actions based on the price of crypto assets.

But it’s not only price feeds that Chainlink offers.

With Chainlink you can get access to any real-world data such as weather data, sports event outcomes, proof of reserves, IoT sensors, and more.

Why not pull the data directly from an API?

Smart contracts could do that but then they would exposed to a single point of failure.

For example, things could go horribly wrong with a smart contract that only pulls price data from the Coingecko API if the Coingecko were to be compromised. 

What Chainlink provides is 

  1. Layers of decentralization and high-quality accurate data
  2. Reliable Oracle node operators
  3. Cost-efficient and decentralized  data delivery
  4. Functionality across blockchains

Where does Chainlink get its data?

Chainlink aggregates data across 3 layers: 

1. Data source i.e. raw data aggregators.

Raw market data is pulled from centralized exchanges such as Binance and Coinbase and decentralized exchanges such as Uniswap and SushiSwap. This data is then aggregated by professional data providers such as Coinmarketcap, Coingecko, Cryptocompare, Cliko, Tiingo, and others. 

2. Chainlink Node operators

Node operators are companies such as Swisscom, T-systems, Chainlayer, LinkPool and Mycelium. Each node operator pulls data from at least 3 different premium data providers and takes the median value.  

3. Oracle network nodes

These are run by DevOps, Telecoms, and infrastructure providers. The chainlink oracles nodes come to a consensus and write the median on-chain. Each decentralized Oracle network is operated by node operators that are geographically distributed, KYCd, and security reviewed. This results in accurate asset prices that are sourced across a broad market that is resistant to API downtime and manipulation.

Three Levels of Aggregation November
Source: Chainlink price feeds simplified, YouTube and this blog post

Each Decentralized Oracle Node leverages off-chain computation and a peer-to-peer network to reduce reporting costs. Responses are collected off-chain in a single Oracle report using Chainlink’s off-chain reporting protocol and delivered on-chain. 

chainlink off chain aggregation

You can find a comprehensive list of data feeds at data.chain.link.

How Chainlink Fetches Data

To fetch and deliver accurate, real-world data to smart contracts Chainlink sources information from various channels. 

A. APIs:

Chainlink oracles are equipped to connect with traditional web APIs, which act as gateways to a plethora of data sources.

API stands for application programming interface and many companies and websites make all or some of their data publicly accessible via an API.

For example, I could use Coingecko’s API to show crypto prices on Elementalcrypto if I wanted to.

Or if I want to do my tax returns I can connect the APIs of the various crypto exchanges I use to Koinly, an online tax calculator. 

The APIs that Chainlink uses can include financial market data, weather information, sports scores, and more. By interfacing with established APIs, Chainlink ensures access to a wide range of real-time and historical data, enabling smart contracts to make informed decisions based on the latest information.

B. Decentralized Data Providers:

In addition to traditional APIs, Chainlink embraces the decentralized nature of blockchain technology by allowing data to be sourced from decentralized providers.

These providers can be other blockchain networks or trusted entities within the Chainlink ecosystem. This approach enhances the network’s resilience, as it avoids reliance on a single point of failure.

C. External Adapters:

Chainlink’s flexibility is further demonstrated through the use of external adapters. These custom modules enable oracles to interact with specific APIs or data sources that may not be directly supported by the network.

This adaptability ensures that virtually any external data feed can be integrated into the Chainlink ecosystem, expanding the network’s capability to fetch data from various sources.

D. Off-chain Data and Computations:

Chainlink’s second iteration, Chainlink 2.0, goes beyond fetching raw data by incorporating off-chain data and computations.

Oracles can perform operations off-chain before delivering the data to smart contracts.

This can include data aggregation, complex calculations, or any other processes that enhance the quality of the information provided to smart contracts. The integration of computation of off-chain data adds another layer of flexibility and customization to Chainlink’s data-fetching capabilities.

What if there aren’t multiple sources for the same data?

In cases where there aren’t multiple sources for the same data, Chainlink will use data from a third-party auditor. You can only trust this data to the degree that you trust the auditor but at least you have an automated transparent way to integrate the data with a blockchain.

About chainlink

The Chainlink network was founded in 2017 after Sergey Nazarov and Steve Ellis raised 32 Million in an ICO (Initial Coin Offering).

By providing off-chain data to smart contracts Chainlink allows blockchains to talk to the outside world. 

Data providers are rewarded in the form of LINK tokens (see how to get Chainlink) and you can even stake LINK to earn a proportion of the fees. Chainlink is consistently in the top 20 coins in terms of market cap.

Apart from providing data from external systems, Chainlink can also help generate a verifiable random number which is useful for gaming and it offers the Chainlink Cross-Chain Interoperability Protocol (CCIP) which allows blockchains to talk to each other. Read What is Chainlink and What Is Chainlink Backed By? for more.

Up Next

Is Chainlink Actually Used? Guide with 12 use cases

Is Chainlink Actually Used

In this post, I will walk you through how chainlink is used. I will show you which apps and companies are using Chainlink and the extent of its usage. Read more.

Best Chainlink Staking Guide: How You Can Earn Rewards

chainlink staking

In this guide, I will walk you through everything you need to know about the Chainlink staking process. We’ll dive into what Chainlink staking is, who is allowed to stake LINK tokens, and how much you could earn. We’ll also review the staking timelines and how Chainlink Staking v0.2 differs from v0.1. Next, I’ll provide you with step-by-step instructions on how to stake your LINK tokens and I’ll explain how long you need to lock up your LINK tokens. Finally, we’ll explore the alternative option of liquid staking and some of the drawbacks of staking. Read more.

Markos Koemtzopoulos is the founder and main writer of ElementalCrypto. He has been a lecturer at the University of Nicosia on cryptocurrencies and DeFi and has taught two courses on crypto and blockchain technology.

Learn About a New
Coin Every Week

Learn About a New
Coin Every Week

Master Crypto Basics

Join over 7,300 subscribers. It’s free.

elementalcrypto newsletter benefits