NEW

Chainlink Data Streams have officially launched on mainnet. Sign up for early access.

Back

Read Data from Data Feeds on Starknet using Starknet Foundry

This example reads the aggregator proxy contract to get the latest values with no account or contract compiling steps required. The [TO_UPDATE] script makes a call directly to the data feed proxy address. By default, the script reads the ETH / USD feed, but you can change the address to read any of the available data feeds on the Starknet Sepolia testnet.

Requirements

Set up your environment

This guide uses the Starknet Foundry toolkit and the Scarb project management tool so you can compile, deploy, and interact with your Starknet smart contracts.

  • Starknet Foundry: Install Starknet Foundry v0.20.1. You can check your current version by running snforge --version or sncast --version in your terminal and install the required version if necessary.

  • Scarb: Install Scarb v2.5.4. You can check your current version by running scarb --version in your terminal and install the required version if necessary.

Alternatively, you can use the asdf tool version manager to install both Starknet Foundry and Scarb. Read the setup instructions for Starknet Foundry and Scarb for more information.

Clone and configure the code examples repository

  1. Clone the chainlink-starknet repository, which includes the example contracts and script for this guide:

    git clone https://github.com/smartcontractkit/chainlink-starknet.git
    
  2. Navigate to the aggregator_consumer [LINK_TO_UPDATE] directory:

    cd chainlink-starknet/examples/contracts/aggregator_consumer/
    

Tutorial

In the ~/chainlink-starknet/examples/contracts/aggregator_consumer/ directory, run the [TO_UPDATE] script:

make [TO_UPDATE]

The script reads the latest data from the ETH / USD Chainlink data feed proxy contract and prints it. Expect an output similar to the following:

Compiling lib(src) src v0.1.0 (~/chainlink-starknet/examples/contracts/aggregator_consumer/scripts/Scarb.toml)
Compiling starknet-contract(src) src v0.1.0 (~/chainlink-starknet/examples/contracts/aggregator_consumer/scripts/Scarb.toml)
Finished release target(s) in 9 seconds
Result::Ok(CallResult { data: [TO_UPDATE] })
command: script run
status: success

The output contains an array with the latest data from the Chainlink data feed proxy contract. The array contains the following values:

Value nameExample valueDescription
round_idTO_UPDATEThe unique identifier of the round of data updates.
answerTO_UPDATEThe actual data provided by the data feed, representing the latest price of an asset in the case of a price feed.
block_numTO_UPDATEThe block number at which the data was recorded on the blockchain.
started_atTO_UPDATEThe timestamp indicating when the data round started, represented as a Unix timestamp.
updated_atTO_UPDATEThe timestamp indicating when the data was last updated, represented as a Unix timestamp.

For a complete list of Chainlink Price Feeds available on Starknet, see the Price Feed Contract Addresses page.

What's next

Stay updated on the latest Chainlink news