# Getting Started with Data Feeds
Source: https://docs.chain.link/data-feeds/getting-started
Last Updated: 2026-07-22

> For the complete documentation index, see [llms.txt](/llms.txt).

Chainlink Data Feeds are the fastest way to connect your smart contracts to real-world data such as asset prices, reserve balances, and L2 sequencer health. Each feed is aggregated by many independent Chainlink node operators and published onchain through a decentralized oracle network, giving your contracts a reliable, manipulation-resistant source of data.

Each price feed has an onchain address and functions that enable contracts to read pricing data from that address, for example the [ETH / USD feed](https://data.chain.link/feeds/ethereum/mainnet/eth-usd).

This guide walks you through reading a Data Feed end-to-end using the [Remix IDE](https://remix.ethereum.org/). You'll deploy a consumer contract on the Sepolia testnet and read the BTC / USD price feed onchain.

## What you'll do

- Deploy a Solidity consumer contract that reads the BTC / USD price feed on Sepolia.
- Retrieve the latest price onchain by calling the consumer contract.
- Learn the key safety checks to apply before moving to production.

The code for reading Data Feeds on Ethereum and other EVM-compatible blockchains is the same for every chain and every feed type. You choose different feeds for different use cases, but the request and response format is always the same. The answer's decimal length and expected value range may differ depending on the feed.


> **CAUTION: Using Data Feeds on L2 networks**
>
> If you are using Chainlink Data Feeds on L2 networks like Arbitrum, OP, and Metis, you must also check the latest
> answer from the L2 Sequencer Uptime Feed to ensure that the data is accurate in the event of an L2 sequencer outage.
> See the [L2 Sequencer Uptime Feeds](/data-feeds/l2-sequencer-feeds) page to learn how to use Data Feeds on L2
> networks.

## Before you begin

If you are new to smart contract development, complete the [Deploy Your First Smart Contract](/quickstarts/deploy-your-first-contract) quickstart first. It walks you through installing and funding a MetaMask wallet and using Remix, which this guide assumes you already know.

You will need:

- A funded wallet on the **Sepolia** testnet (chain ID `11155111`). Get testnet ETH from a [Sepolia faucet](/resources/link-token-contracts/#sepolia-testnet).
- The [Remix IDE](https://remix.ethereum.org/) open in your browser. No local installation required.
- MetaMask configured for Sepolia.

> **NOTE: Why a proxy?**
>
> Consumer contracts call a *proxy* contract, which forwards reads to the current *aggregator*. When Chainlink
> upgrades an aggregator, the proxy is repointed to the new implementation and your consumer contract keeps working
> unchanged. Always read from the proxy address listed on the
> [Price Feed Addresses](/data-feeds/price-feeds/addresses) page, not from the underlying aggregator.

## Step 1: Examine the sample contract

The example contract below reads the latest answer from the [BTC / USD feed](/data-feeds/price-feeds/addresses) on Sepolia. It targets Solidity `^0.8.7`. You can modify it to read any of the [Types of Data Feeds](/data-feeds#types-of-data-feeds).

```sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED
 * VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */

/**
 * If you are reading data feeds on L2 networks, you must
 * check the latest answer from the L2 Sequencer Uptime
 * Feed to ensure that the data is accurate in the event
 * of an L2 sequencer outage. See the
 * https://docs.chain.link/data-feeds/l2-sequencer-feeds
 * page for details.
 */
contract DataConsumerV3 {
  AggregatorV3Interface internal dataFeed;

  /**
   * Network: Sepolia
   * Aggregator: BTC/USD
   * Address: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43
   */
  constructor() {
    dataFeed = AggregatorV3Interface(0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43);
  }

  /**
   * Returns the latest answer.
   */
  function getChainlinkDataFeedLatestAnswer() public view returns (int256) {
    // prettier-ignore
    (
      /* uint80 roundId */
      ,
      int256 answer,
      /*uint256 startedAt*/
      ,
      /*uint256 updatedAt*/
      ,
      /*uint80 answeredInRound*/
    ) = dataFeed.latestRoundData();
    return answer;
  }
}
```

The contract has the following components:

- The `import` line brings in [`AggregatorV3Interface`](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.3.0/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol) — the Solidity interface that every Chainlink v3 price feed proxy implements. It exposes `latestRoundData()`, `getRoundData()`, `decimals()`, and `version()`. The sample uses `latestRoundData` to fetch the current price.
- The `constructor()` initializes a `dataFeed` object that uses `AggregatorV3Interface` pointing at the proxy aggregator deployed at 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43. This is the proxy address for the Sepolia `BTC / USD` feed. The proxy lets the aggregator be upgraded without breaking consumer contracts.
- The `getChainlinkDataFeedLatestAnswer()` function calls your `dataFeed` object and runs the `latestRoundData()` function and returns the `answer` variable. When you deploy the contract, it initializes the `dataFeed` object to point to the aggregator at 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43, which is the proxy address for the Sepolia `BTC / USD` data feed. Your contract connects to that address and executes the function. The aggregator connects with several oracle nodes and aggregates the pricing data from those nodes. The response from the aggregator includes several variables, but `getChainlinkDataFeedLatestAnswer()` returns only the `answer` variable. The full response includes `roundId`, `startedAt`, `updatedAt`, and `answeredInRound` — see the [API Reference](/data-feeds/api-reference) for details.

## Step 2: Compile the contract in Remix

1. [Open the example contract](https://remix.ethereum.org/#url=https://docs.chain.link/samples/DataFeeds/DataConsumerV3.sol) in Remix. Remix loads the file and its imports automatically.

   <div class="remix-callout">
     <a href="https://remix.ethereum.org/#url=https://docs.chain.link/samples/DataFeeds/DataConsumerV3.sol">Open the contract in Remix</a>
   </div>

2. On the left sidebar, click the **Solidity Compiler** tab.

   (Image: Image)

3. Keep the default compiler settings and click **Compile DataConsumerV3.sol**. Remix auto-detects the compiler version from the `pragma` statement. You can ignore warnings about unused local variables — the example destructures `latestRoundData()` but only uses `answer`.

   (Image: Image)

## Step 3: Deploy to Sepolia

1. Open MetaMask and switch to the **Sepolia** network. If you don't have it configured, you can find the chain ID and RPC details on the [LINK Token Contracts](/resources/link-token-contracts#sepolia-testnet) page.

2. In Remix, open the **Deploy & Run Transactions** tab and set the **Environment** to **Injected Provider - MetaMask**. This contract must run in a Web3 context because it reads from another onchain contract. Running in the JavaScript VM will not work.

   (Image: Image)

3. Because the example has several imports, Remix may default to a different contract. In the **Contract** dropdown, explicitly select `DataConsumerV3`.

   (Image: Image)

4. Click **Deploy**. MetaMask opens and asks you to confirm the deployment transaction. Verify the network is Sepolia before confirming — onchain transactions are irreversible.

   (Image: Image)

5. In the MetaMask prompt, click **Confirm** to approve the transaction and spend the testnet ETH required to deploy.

   (Image: Image)

6. After a few seconds, the transaction completes and your contract appears under **Deployed Contracts** in Remix. Click the contract dropdown to expand its variables and functions.

   (Image: Image)

## Step 4: Read the latest price onchain

1. Click **getChainlinkDataFeedLatestAnswer** to call the function. The latest answer from the aggregator appears just below the button.

   (Image: Image)

2. The returned answer is an integer with no decimal point. The BTC / USD feed uses **8 decimals**, so an answer of `3030914000000` represents a BTC / USD price of `30309.14`. Each feed uses a different number of decimals — you can find the exact value on the [Price Feed Addresses](/data-feeds/price-feeds/addresses) page by enabling **Show more details**.

> **TIP: Always scale by `decimals()`**
>
> Never hardcode the decimal count. Call `decimals()` on the feed and scale the answer programmatically. This keeps
> your contract correct if you later point it at a feed with a different precision (e.g., some feeds use 18 decimals).

## Step 5: Read the same feed offchain (addendum)

You can also read Data Feeds directly from the feed proxy without deploying a consumer contract. This is useful for backends, bots, dashboards, and pre-trade checks. No consumer contract is required — the feed proxy is a public contract and `latestRoundData()` is a `view` function, so anyone can call it directly from a script or CLI.

The lowest-friction offchain read is a single `cast call` (requires [Foundry](https://book.getfoundry.sh/) installed):

```bash
cast call 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 "latestRoundData()(uint80,int256,uint256,uint256,uint80)" --rpc-url $SEPOLIA_RPC_URL
```

## Before you go to production

The example intentionally omits the safety checks a production integration needs. Before shipping, review the following points and the [Developer Responsibilities](/data-feeds/developer-responsibilities) page.

### Check `updatedAt` and staleness

`latestRoundData()` returns `updatedAt` (the timestamp of the latest round) and `answeredInRound` (the round in which the answer was finalized). Always verify the feed is fresh:

```solidity
(uint80 roundId, int256 answer, , uint256 updatedAt, uint80 answeredInRound) = dataFeed.latestRoundData();

require(answeredInRound >= roundId, "Stale price");
require(block.timestamp - updatedAt < TIMEOUT, "Stale price");
```

Choose a `TIMEOUT` that matches your application's risk tolerance — shorter for trading, longer for less time-sensitive use cases.

### Use the right feed for your asset

Not all feeds are equal. Low-liquidity assets are more exposed to market manipulation. Review [Selecting Quality Data Feeds](/data-feeds/selecting-data-feeds) and the [Data Feed Categories](/data-feeds/selecting-data-feeds#data-feed-categories) before choosing a feed.

### Handle L2 sequencer risk

On L2s, a sequencer outage can cause stale or incorrect prices. Always pair L2 price feeds with a check on the [L2 Sequencer Uptime Feed](/data-feeds/l2-sequencer-feeds). The `DataConsumerWithSequencerCheck` sample shows the pattern. Try it out in Remix below:

[Open DataConsumerWithSequencerCheck.sol in Remix](https://remix.ethereum.org/#url=https://docs.chain.link/samples/DataFeeds/DataConsumerWithSequencerCheck.sol)

### Audit your integration

The sample code is unaudited and hardcodes values for clarity. Before production, complete your own audit, review your dependencies, and apply the risk-mitigation practices described in [Developer Responsibilities](/data-feeds/developer-responsibilities).

## FAQ

### Do I need a consumer contract to read a Data Feed?

**Only if another smart contract needs the price onchain.** A consumer contract exists to wrap a feed read in your own contract's logic so that *your other contracts* can use the price onchain — for collateral checks, settlements, circuit breakers, and so on. The read is atomic with your onchain action and verifiable on the blockchain.

If you only need the price in an offchain system (a backend, bot, dashboard, or pre-trade check), you do **not** need a consumer contract. The feed proxy is a public contract and `latestRoundData()` is a `view` function — anyone can call it directly from a script using `cast`, ethers.js, or viem. See [Step 5: Read the same feed offchain](#step-5-read-the-same-feed-offchain-addendum) on this page, or the [Foundry](/data-feeds/getting-started-foundry#step-5-read-the-same-feed-offchain-no-consumer-contract-required) and [Hardhat](/data-feeds/getting-started-hardhat#step-5-read-the-same-feed-offchain-no-consumer-contract-required) offchain read sections.

|                                 | Consumer contract (onchain)           | Direct read (offchain)               |
| ------------------------------- | ------------------------------------- | ------------------------------------ |
| **Who needs the price?**        | Another smart contract                | A script, backend, bot, or dashboard |
| **Gas cost?**                   | Pay to deploy + gas for onchain reads | Free (view calls from a script)      |
| **Deployment required?**        | Yes                                   | No                                   |
| **Atomic with onchain action?** | Yes                                   | No                                   |

### Remix says "contract not found" when deploying

In the **Contract** dropdown on the Deploy & Run Transactions tab, explicitly select `DataConsumerV3`. When a file has multiple imports, Remix defaults to the first contract alphabetically, which may not be the one you want to deploy.

### The MetaMask transaction reverted on deployment

Make sure MetaMask is set to the **Sepolia** network (chain ID `11155111`) before confirming. If you're on another network, the deployment will revert or land on the wrong chain. Also confirm your wallet has enough testnet ETH to cover gas — check a [Sepolia faucet](/resources/link-token-contracts/#sepolia-testnet) if needed.