Read Data from Data Feeds on Starknet using Starknet Foundry

In this example, you will read from a Chainlink price feed on Starknet using the Starknet Foundry toolkit. You will call the latest_round_data function on the ETH / USD aggregator proxy contract to read the latest round of data.

Requirements

Make sure you have the Starknet Foundry toolkit installed. You can check your current version by running snforge --version or sncast --version in your terminal. Follow the installation guide if necessary.

Tutorial

Run the following command to read data from the ETH / USD data feed proxy contract:

sncast \
  --url https://starknet-sepolia.public.blastapi.io/rpc/v0_7 \
  call \
  --contract-address 0x228128e84cdfc51003505dd5733729e57f7d1f7e54da679474e73db4ecaad44 \
  --function "latest_round_data" \

Expect an output similar to the following:

command: call
response: [0x10000000000000000000000000000320c, 0x5293770eb1, 0xd44d, 0x6606b8cc, 0x6606b8a2]

The example output contains an array with the hex-encoded latest round of data for the ETH / USD price feed. The array contains the following values:

Value nameHex-encoded valueDecoded valueDescription
round_id0x10000000000000000000000000000320c340282366920938463463374607431768224268The unique identifier of the data round
answer0x5293770eb1354661371569The actual data provided by the data feed, representing the latest price of an asset in the case of a price feed
block_num0xd44d54349The block number at which the data was recorded on the blockchain
started_at0x6606b8cc1711716556The Unix timestamp indicating when the data round started
updated_at0x6606b8a21711716514The Unix timestamp indicating when the data was last updated

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

Note: This example uses a Blast API RPC endpoint. You can interact with the network using any other Starknet Sepolia RPC provider, such as Alchemy or Infura.

What's next

Get the latest Chainlink content straight to your inbox.