百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

solana-starter-kit

> 编程语言
开源

在 Solana 上使用 Chainlink 的示例代码

193 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

在 Solana 上使用 Chainlink 的示例代码

Chainlink Solana Starter Kit

The Chainlink Solana Starter Kit is an Anchor based program and client that shows developers how to use and interact with Chainlink Price Feeds on Solana. The demo is configured to run on the Devnet cluster, and is comprised of an on-chain program written in Rust, and an off-chain client written in JavaScript. The program takes parameters and account information from the off-chain client, retrieves the latest price data from the specified Chainlink Price Feed on Devnet, then writes the data out to the specified account, which can then be read by the off-chain client.

Environment Variables

The following environment variables must be set before running the scripts:

Variable Description Required For
EVM_PRIVATE_KEY The private key for the EVM account All EVM chain operations
EVM_RPC_URL RPC URL for Ethereum Sepolia Operations on Ethereum Sepolia
AVAX_RPC_URL RPC URL for Avalanche Fuji Operations on Avalanche Fuji
SOLANA_RPC_URL RPC URL for Solana Devnet (defaults to public endpoint if not set) Operations on Solana Devnet

Setting up Environment Variables

Create a .env file in the root directory with the following format:

EVM_PRIVATE_KEY=your_private_key_here
EVM_RPC_URL=https://your-ethereum-sepolia-rpc-url
AVAX_RPC_URL=https://your-avalanche-fuji-rpc-url
SOLANA_RPC_URL=https://your-solana-devnet-rpc-url

Important: The RPC URLs must be valid and accessible for the scripts to work. If an RPC URL is not provided for a chain, an error will be thrown when attempting to use that chain.

Running the example on Devnet

Requirements

  • Node.js v20+ (v23.11.0 recommended)
  • Rust - we recommend rustc version 1.87 and above
  • Solana CLI - we recommend v0.31.1
  • Anchor - we recommend v2.1.21 and above.
  • A C compiler such as the one included in GCC.

Building and Deploying the Consumer Program

First, ensure that you're in the solana-starter-kit directory in this repository

cd ./solana-starter-kit

Next step is to install all of the required dependencies:

bash
npm install

Note for Apple M1 chipsets: You will need to perform an extra step to get the Anchor framework installed manually from source, as the NPM package only support x86_64 chipsets currently, please run the following command to install it manually:

cargo install --git https://github.com/coral-xyz/anchor --tag v0.31.1 anchor-cli --locked

Next, generate a new wallet:

solana-keygen new -o id.json

You should see the public key in the terminal output. Alternatively, you can find the public key with the following CLI command:

solana-keygen pubkey id.json

Next, airdrop 5 SOL tokens into your new account. Be sure to replace both instances of with your wallet's public key from the previous step:

solana airdrop $(solana address --keypair id.json) --url https://api.devnet.solana.com

Confirm that you have received the 5 SOL by running solana balance --keypair id.json.

Next, build the program:

anchor build

Before you deploy the chainlink_solana_demo program, you must update its public key in ./programs/chainlink_solana_demo/src/lib.rs:

declare_id!("####GEg__SOME__KEY__HERE__F2TsL#####");

This declare_id! macro is used to hardcode the program's public key directly into the program's bytecode.

To update this public key, you need to run the command below:

anchor keys sync

After this command, check ./programs/chainlink_solana_demo/src/lib.rs again. The declare_id! line will be updated with your program address, for example:

declare_id!("JC16qi56dgcLoaTVe4BvnCoDL6FhH5NtahA7jmWZFdqm");

To avoid having to add --keypair id.json to future commands now is a good time to add the following in your terminal:

export ANCHOR_WALLET="./id.json" --> include the quotes

Finally, because you updated the source code with its generated public key, you need to rebuild the program to regenerate the associated files for deployment, and then it can be deployed to devnet

anchor build
anchor deploy --provider.cluster devnet

Once you have successfully deployed the program, the terminal output will specify the program ID. Make sure you're looking for the Program ID of the chainlink_solana_demo program.

The Program ID must match the value in ./programs/chainlink_solana_demo/src/lib.rs.

The declare_id! and your deployed program ID should be the same. If they're different, it could indicate:

  • You didn't run anchor keys sync after the initial build
  • You didn't rebuild after syncing keys
  • There was an issue during the deployment process

Once again, take note of this Program ID, as it will be required when executing the client:

Deploying workspace: https://api.devnet.solana.com
Upgrade authority: ./id.json
Deploying program "chainlink_solana_demo"...
Program path: ./target/deploy/chainlink_solana_demo.so...
Program Id: JC16qi56dgcLoaTVe4BvnCoDL6FhH5NtahA7jmWZFdqm

Running the Client

Next we set up the JavaScript client that interacts with our deployed program on Devnet.

The first step is to set the Anchor environment variables. These are required by the Anchor framework to determine which provider to use and which wallet to use for interacting with the deployed program:

bash
export ANCHOR_PROVIDER_URL='https://api.devnet.solana.com'
export ANCHOR_WALLET='./id.json'

Now you are ready to run the JavaScript client. Be sure to pass Chainlink data feed address that you want to query. This can be taken from the Chainlink Solana Data Feeds page, and the value will be defaulted to the Devnet SOL/USD feed address if you don't specify a value. In this example, we specified the ETH/USD feed:

bash
node client.js --feed	669U43LNHx7LsVj95uYksnhXUfWKDsdzVqev3V4Jpw3P

The client will generate a new account and pass it to the deployed program, which will then populate the account with the current price from the specified price feed. The client will then read the price from the account, and output the value to the console.

…

Running the Read Only Clients

To facilitate the scenario of purely requiring Chainlink Price Feed data off-chain, we have also included a second read-data client that queries a specified price feed and returns the latest price data. This version of the client does not generate a transaction, and therefore requires no accounts created or transaction fees. To run the read-data client, first you should ensure you have set the required Anchor environment variables. You can skip this step if you already did it earlier before running the normal client:

bash
export ANCHOR_PROVIDER_URL='https://api.devnet.solana.com'
export ANCHOR_WALLET='./id.json'

Next, you can set the value of the CHAINLINK_FEED_ADDRESS static variable to the value of the Price Feed account address that you wish to query. This example queries the ETH/USD feed on Devnet:

const CHAINLINK_FEED_ADDRESS="669U43LNHx7LsVj95uYksnhXUfWKDsdzVqev3V4Jpw3P"

Once you save your file, you can then execute the client. There is a Typescript and a JavaScript version:

Typescript:

bash
yarn read-data

JavaScript:

bash
node read-data.js

The client will query the specified price feed using the published Chainlink Solana NPM package, and will then continuously just print the latest price to the console.

pappas99@Pappas solana-starter-kit % yarn read-data
> @ read-data /Users/pappas99/GitHub/22-hackathon/solana-starter-kit
> ts-node ./read-data.ts

301296000000
301250000000
301215000000
301205000000
301331000000

Testing Data Feeds Contracts

You can execute the integration test with the following command

bash
anchor test

The integration test checks that the value of the specified price feed account (defaulted to SOL/USD) on Devnet is greater than 0.

bash
 solana-starter-kit

Price Is: 105.52
    ✔ Query SOL/USD Price Feed! (4521ms)

  1 passing (5s)

✨  Done in 10.49s.

If you'd like to run the test after initial deployment of the contracts, you can run the tests directly via yarn.

bash
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts

You will be asked to provide anchor environment variables. See .env.example for details.

Cross-Chain Interoperability Protocol (CCIP)

This repository also includes scripts and libraries for Chainlink CCIP, enabling cross-chain communication between Solana and EVM-compatible blockchains.

CCIP Features

  • Token Transfers: Send tokens from EVM chains to Solana and vice versa
  • Arbitrary Messaging: Send custom data between chains
  • Multi-Chain Support: Works with Ethereum, Base, Optimism, BSC, Arbitrum, and more
  • CCIP Receivers: Deploy and manage programs that receive cross-chain messages

Cross-chain token (CCT) pool setup (burn-mint pools, admin registry, ALT management) lives in ccip-solana-bs58-generator, not this repo.

Quick Start with CCIP

Send Tokens from Ethereum to Solana

bash
# Estimate fees (read-only, no private key required)
yarn evm:check-fee

# Get test tokens
yarn evm:token:drip

# Send BnM tokens to Solana
yarn evm:transfer --token 0x779877A7B0D9E8603169DdbD7836e478b4624789 --amount 1000000000000000000

Send Tokens from Solana to Ethereum

bash
# Delegate authority for CCIP transfers
yarn svm:token:delegate

# Send tokens cross-chain
yarn svm:token-transfer --token-mint YourTokenMintAddress --token-amount 1000000

CCIP Documentation

For comprehensive CCIP documentation:

  • CCIP Scripts Overview - Script commands and quick start
  • SVM Scripts Guide - Detailed Solana operations
  • EVM Scripts Guide - Detailed EVM operations
  • SVM SDK Documentation - Solana SDK reference
  • EVM SDK Documentation - EVM SDK reference

CCIP Explorer

Track your cross-chain messages on the CCIP Explorer

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言