{"id":19107364,"url":"https://github.com/smartcontractkit/solana-starter-kit","last_synced_at":"2025-04-06T06:13:56.850Z","repository":{"id":37051039,"uuid":"454125764","full_name":"smartcontractkit/solana-starter-kit","owner":"smartcontractkit","description":"Example code for using Chainlink on Solana","archived":false,"fork":false,"pushed_at":"2024-08-08T06:52:38.000Z","size":296,"stargazers_count":181,"open_issues_count":2,"forks_count":119,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-30T05:05:32.612Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartcontractkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-31T18:38:13.000Z","updated_at":"2025-03-12T02:22:25.000Z","dependencies_parsed_at":"2024-08-08T08:30:08.340Z","dependency_job_id":"132a2484-d923-4a73-a926-d2941bc91789","html_url":"https://github.com/smartcontractkit/solana-starter-kit","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fsolana-starter-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fsolana-starter-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fsolana-starter-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fsolana-starter-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartcontractkit","download_url":"https://codeload.github.com/smartcontractkit/solana-starter-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441062,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T04:12:20.530Z","updated_at":"2025-04-06T06:13:56.816Z","avatar_url":"https://github.com/smartcontractkit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cbr/\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://chain.link\" target=\"_blank\"\u003e\n\u003cimg src=\"./solana_logo.png\" width=\"225\" alt=\"Chainlink Solana logo\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr/\u003e\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/smartcontractkit/solana-starter-kit)\n\n\n# Chainlink Solana Starter Kit\nThe Chainlink Solana Starter Kit is an [Anchor](https://project-serum.github.io/anchor/getting-started/introduction.html) based program and client that shows developers how to use and interact with [Chainlink Price Feeds on Solana](https://docs.chain.link/solana/). The demo is configured to run on the [Devnet cluster](https://docs.solana.com/clusters#devnet), 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.\n\n## Running the example on Devnet\n\n### Requirements\n- [NodeJS 12](https://nodejs.org/en/download/) or higher\n- [Rust](https://www.rust-lang.org/tools/install)\n- [Solana CLI](https://docs.solanalabs.com/cli/install)\n- [Anchor](https://book.anchor-lang.com/getting_started/installation.html)\n- A C compiler such as the one included in [GCC](https://gcc.gnu.org/install/).\n\n### Building and Deploying the Consumer Program\n\nFirst, ensure that you're in the `solana-starter-kit` directory in this repository\n\n```\ncd ./solana-starter-kit\n```\n\nNext step is to install all of the required dependencies:\n\n```\nnpm install\n```\n\n**Note for [Apple M1](https://en.wikipedia.org/wiki/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:\n\n```\ncargo install --git https://github.com/coral-xyz/anchor --tag v0.30.1 anchor-cli --locked\n```\n\n\nNext, generate a new wallet:\n\n```\nsolana-keygen new -o id.json\n```\n\nYou should see the public key in the terminal output. Alternatively, you can find the public key  with the following CLI command:\n\n```\nsolana-keygen pubkey id.json\n```\n\nNext, airdrop 5 SOL tokens into your new account. Be sure to replace both instances of \u003cRECIPIENT_ACCOUNT_ADDRESS\u003e with your wallet's public key from the previous step:\n\n```\nsolana airdrop 5 $(solana-keygen pubkey ./id.json) --url https://api.devnet.solana.com\n```\n\nNext, build the program:\n\n```\nanchor build\n```\n\nThe build process generates the keypair for your program's account. Before you deploy your program, you must update this public key in this line `lib.rs` file.\n```\ndeclare_id!(\"GEgDWT7Cc8H5S1o2YnTp3umiciazQj5fKbftPXkc2TsL\");\n``` \nTo do this, you need to run the command below:\n```\nanchor keys sync\n```\n\nAfter this command, check the file `lib.rs` again. The line will be updated as below (you may find diffretn value within the `declare_id!()`)\n\n```\ndeclare_id!(\"JC16qi56dgcLoaTVe4BvnCoDL6FhH5NtahA7jmWZFdqm\");\n```\n\nFinally, because you updated the source code with the generated program ID, you need to rebuild the program to regenerate the associated files for deployment, and then it can be deployed to devnet\n\n```\nanchor build\nanchor deploy --provider.cluster devnet\n```\n\nOnce you have successfully deployed the program, the terminal output will specify the program ID of the program, it should match the value you inserted into the `lib.rs` file and the `Anchor.toml` file. Once again, take note of this Program ID, as it will be required when executing the client:\n\n```\nDeploying workspace: https://api.devnet.solana.com\nUpgrade authority: ./id.json\nDeploying program \"chainlink_solana_demo\"...\nProgram path: ./target/deploy/chainlink_solana_demo.so...\nProgram Id: JC16qi56dgcLoaTVe4BvnCoDL6FhH5NtahA7jmWZFdqm\n```\n\n### Running the Client\n\nThe first step is to set the Anchor [environment variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html). These are required by the Anchor framework to determine which provider to use and which wallet to use for interacting with the deployed program:\n\n```\nexport ANCHOR_PROVIDER_URL='https://api.devnet.solana.com'\nexport ANCHOR_WALLET='./id.json'\n```\n\nNow 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](https://docs.chain.link/docs/solana/data-feeds-solana/), 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:\n\n```\nnode client.js --feed\t669U43LNHx7LsVj95uYksnhXUfWKDsdzVqev3V4Jpw3P\n```\n\nThe 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.\n\n```\nRunning client...\npriceFeedAccount public key: DNQBqwGijKix2EmKhMMaftZgSywcbfnQZSzfDyEMEfLf\nuser public key: GWKzUMdSF8Y4xQ3JANTChkaJDFE4UdkvAkHCknmJtJUX\nFetching transaction logs...\n[\n  'Program BrEqc6zHVR77jrP6U6WZLUV24AZ9UnHrWfDQTDV7VoDY invoke [1]',\n  'Program log: Instruction: Execute',\n  'Program 11111111111111111111111111111111 invoke [2]',\n  'Program 11111111111111111111111111111111 success',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny invoke [2]',\n  'Program log: Instruction: Query',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny consumed 2551 of 1360424 compute units',\n  'Program return: HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny RZ0GABn5swcAAAAA3ltiYgAVg8dFAAAAAAAAAAAAAAA=',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny success',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny invoke [2]',\n  'Program log: Instruction: Query',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny consumed 2245 of 1328033 compute units',\n  'Program return: HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny CQAAAEVUSCAvIFVTRA==',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny success',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny invoke [2]',\n  'Program log: Instruction: Query',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny consumed 1826 of 1295650 compute units',\n  'Program return: HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny CA==',\n  'Program HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny success',\n  'Program log: ETH / USD price is 2997.00000000',\n  'Program BrEqc6zHVR77jrP6U6WZLUV24AZ9UnHrWfDQTDV7VoDY consumed 109699 of 1400000 compute units',\n  'Program return: BrEqc6zHVR77jrP6U6WZLUV24AZ9UnHrWfDQTDV7VoDY CA==',\n  'Program BrEqc6zHVR77jrP6U6WZLUV24AZ9UnHrWfDQTDV7VoDY success'\n]\nPrice Is: 2997\nSuccess\n```\n\n### Running the Read Only Clients\n\nTo 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:\n\n```\nexport ANCHOR_PROVIDER_URL='https://api.devnet.solana.com'\nexport ANCHOR_WALLET='./id.json'\n```\n\nNext, you can set the value of the `CHAINLINK_FEED_ADDRESS` static variable to the value of the [Price Feed account address](https://docs.chain.link/docs/solana/data-feeds-solana/) that you wish to query. This example queries the ETH/USD feed on Devnet:\n\n\n```\nconst CHAINLINK_FEED_ADDRESS=\"669U43LNHx7LsVj95uYksnhXUfWKDsdzVqev3V4Jpw3P\"\n```\n\nOnce you save your file, you can then execute the client. There is a [Typescript](https://github.com/smartcontractkit/solana-starter-kit/blob/main/read-data.ts) and a [JavaScript](https://github.com/smartcontractkit/solana-starter-kit/blob/main/read-data.js) version:\n\nTypescript:\n\n```\nnpm run read-data\n```\n\nJavaScript:\n```\nnode read-data.js\n```\n\nThe client will query the specified price feed using the published [Chainlink Solana NPM package](https://www.npmjs.com/package/@chainlink/solana-sdk), and will then continuously just print the latest price to the console.\n\n```\npappas99@Pappas solana-starter-kit % npm run read-data\n\u003e @ read-data /Users/pappas99/GitHub/22-hackathon/solana-starter-kit\n\u003e ts-node ./read-data.ts\n\n301296000000\n301250000000\n301215000000\n301205000000\n301331000000\n```\n\n\n### Testing\n\nYou can execute the [integration test](./tests/chainlink-solana-demo-int-test.ts) with the following command\n\n```bash\nanchor test\n```\n\nThe integration test checks that the value of the specified price feed account (defaulted to SOL/USD) on Devnet is greater than 0.\n\n```bash\n solana-starter-kit\n\nPrice Is: 105.52\n    ✔ Query SOL/USD Price Feed! (4521ms)\n\n\n  1 passing (5s)\n\n✨  Done in 10.49s.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartcontractkit%2Fsolana-starter-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartcontractkit%2Fsolana-starter-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartcontractkit%2Fsolana-starter-kit/lists"}