# Using Data Feeds on Stellar
Source: https://docs.chain.link/data-feeds/stellar

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

[Stellar](https://stellar.org/) is a Layer 1 blockchain that uses [Soroban](https://soroban.stellar.org/) smart contracts written in [Rust](https://www.rust-lang.org/). Chainlink Data Feeds on Stellar use a single cache contract that serves every feed. Instead of a per-feed contract address, you select a feed by its 32-byte `data_id`.

A `data_id` is a 32-byte identifier for a feed, similar to how a contract address identifies a feed on EVM chains. It is the same value as the **Feed ID** shown in the [Price Feed Contract Addresses](/data-feeds/price-feeds/addresses?network=stellar) table. You pass the `data_id` to the cache contract to read that feed's data.

## How Stellar Data Feeds work

Data Feeds on Stellar use a cache contract that the Chainlink oracle network writes into. Consumers read feeds directly from the cache by passing a 32-byte `data_id`:

- **Cache contract**: A single cache contract serves every feed. The Chainlink oracle network writes round data into the cache, and consumers read it by passing the `data_id` for the feed they need. The cache address stays stable across upgrades.

Consumers select a feed by passing its 32-byte `data_id` to the cache. You can find the `data_id` for each feed on the [Price Feed Contract Addresses](/data-feeds/price-feeds/addresses?network=stellar) page with Stellar selected.

## Supported networks

Chainlink Data Feeds are available on the following Stellar networks:

- [Stellar Testnet](https://stellar.org/developers/guides/concepts/networks#testnet)
- [Stellar Mainnet (Pubnet)](https://stellar.org/developers/guides/concepts/networks#public-network)

## Available data feeds on Stellar

The following table shows all available data feeds on Stellar. Each feed is identified by its `data_id` (the Feed ID), which you pass to the cache contract to read that feed's data.

## Cache contract addresses

The cache contract address is the same for every feed on a given network. You only ever interact with the cache.

- **Stellar Testnet**: CAVLZXJDRGOS6UZ7BHYTYW7STQMZIOCUJIVRMT7JE7T5F6JIA3LPAOVW
- **Stellar Mainnet (Pubnet)**: CAAFKBE6AMTERARISMMT4TCC4UGNO35XCKQNC5XVLL5WY5GRWXH6AMIO

## Reader interface

Consumers call the following functions on the cache contract. The interface is defined in the [chainlink-stellar](https://github.com/smartcontractkit/chainlink-stellar/tree/main/contracts/common/interfaces/src/data_feeds_cache.rs) repository.

| Function                       | Returns                                               |
| ------------------------------ | ----------------------------------------------------- |
| `latest_round(data_ids)`       | The most recent round for each requested `data_id`    |
| `get_round(data_id, round_id)` | A specific historical round                           |
| `decimals(data_ids)`           | Decimal places for each requested `data_id`           |
| `description(data_ids)`        | Human-readable pair name for each requested `data_id` |

### Round structure

A round returned by the cache carries the following fields:

| Field        | Description                                                                                                                                           |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `round_id`   | The unique identifier of the round                                                                                                                    |
| `answer`     | The answer for the feed, represented as an `I256`                                                                                                     |
| `timestamp`  | The Unix timestamp in seconds when the round was recorded                                                                                             |
| `ledger_seq` | The [Stellar ledger](https://developers.stellar.org/docs/learn/fundamentals/stellar-data-structures/ledgers) sequence at which the round was recorded |
| `primary`    | Indicates whether the round is the primary round for the feed                                                                                         |

## Error handling

When you call the cache, the contract can return a `CacheError`. The following cases describe what each error means for a consumer:

| Error               | Meaning                                                                                                                                                                                                                                   |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `FeedNotConfigured` | The `data_id` you passed does not correspond to a configured feed. Check that you are using the correct `data_id` from the [Price Feed Contract Addresses](/data-feeds/price-feeds/addresses?network=stellar) page with Stellar selected. |
| `InvalidDataId`     | The `data_id` you passed is invalid.                                                                                                                                                                                                      |
| `FeedFrozen`        | The feed is frozen and cannot be read.                                                                                                                                                                                                    |

## How long a round is available

A round is stored in the cache contract's temporary storage with a retention period of `3,110,400` ledgers. After this period, a round can no longer be read from the cache.

## Getting started

You can read Chainlink Data Feeds on Stellar either offchain or onchain. Both methods read the same data from the cache contract, differing only in where the read happens.

- **[Using Data Feeds Offchain](/data-feeds/stellar/using-data-feeds-off-chain)**: Read a feed via Soroban RPC simulation using `stellar-cli` and the Stellar JavaScript SDK. This method is for applications that need to read feed data without deploying a contract.

- **[Using Data Feeds Onchain](/data-feeds/stellar/using-data-feeds-on-chain)**: Deploy a Soroban contract in Rust that calls the cache and reads a price. This method is for applications that need to read feed data directly within a smart contract.

Each guide lists the tools and requirements you need to complete it.

## Answer precision

The cache stores every answer at a fixed `18` decimal places (`DECIMALS`). Feeds sourced at a lower precision, such as `8` decimals, are scaled up to `18` on write, so the stored value is always `18`-decimal regardless of the feed's native precision. When you read a round, the `answer` is returned at `18` decimal places.

> **DANGER: Select quality data feeds**
>
> Be aware of the quality of the data that you use. [Learn more about making responsible data quality decisions](/data-feeds/selecting-data-feeds).