Chainlink Data Feeds are the quickest way to access market prices for real-world assets. This guide demonstrates how to read Chainlink Data Feeds on the Solana Devnet using off-chain examples in the Chainlink Solana Starter Kit. To learn how to use Data Feeds in your on-chain Solana programs, see the Using Data Feeds On-Chain guide.
To get the full list of Chainlink Data Feeds on Solana, see the Solana Feeds page.
Select quality data feeds
Be aware of the quality of the data that you use. Learn more about making responsible data quality decisions.
Table of contents:
Before you begin, set up your environment for development on Solana:
Install Git if it is not already configured on your system.
Install Node.js 14 or higher. Run
node --version to verify which version you have installed:
Install Yarn to simplify package management and run code samples.
npm i -g @project-serum/anchor-cli
On some operating systems, you might need to build and install Anchor locally. See the Anchor documentation for instructions.
After you install the required tools, clone the example code from the solana-starter-kit repository.
In a terminal, clone the solana-starter-kit repository and change to the
git clone https://github.com/smartcontractkit/solana-starter-kit && cd ./solana-starter-kit
You can see the complete code for the example on GitHub.
./solana-starter-kit directory, install Node.js dependencies defined in the
Create a temporary Solana wallet to use for this example. Because your application runs off-chain and does not run any functions or alter data on-chain, the wallet does not require any SOL tokens to function.
solana-keygen new --outfile ./id.json
Set the Anchor environment variables. Anchor uses these to determine which wallet to use and Solana cluster to use. For a list of available networks and endpoints, see the Solana Cluster RPC Endpoints documentation.
export ANCHOR_PROVIDER_URL=https://api.devnet.solana.com && export ANCHOR_WALLET=./id.json
yarn run read-data
The example code retrieves and prints the current price feed data until you close the application:
yarn run v1.22.18 $ ts-node ./read-data.ts 9731000000 9732000000 9730839909 9734000000