Solana API Quickstart
Quickstart guide for building on Solana
Don’t have an API key?
Sign up to start building on Solana. Get started for free
Getting Started Instructions
1. Choose a package manager (npm or yarn)
For this guide, we will be using npm or yarn as our package manager to install either alchemy-sdk
or any other packages.
npm
To get started with npm
, follow the documentation to install Node.js and npm
for your operating system: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
yarn
To get started with yarn
, follow these steps: https://classic.yarnpkg.com/lang/en/docs/install
2. Set up your project (npm or yarn)
3. Install Solana Web3.js Library
Run the following command to install the Solana Web3.js library with npm or yarn.
4. Make your first request
You are all set now to use Solana API and make your first request. For instance, lets make a request to get latest slot
. Create an index.js
file and paste the following code snippet into the file.
5. Run script
To run the above node script, use cmd node index.js
, and you should see the output.
Leverage Alchemy’s AccountsDB Infrastructure for Solana RPC Requests!
The most expensive Solana RPC requests involve account scans, such as getProgramAccounts
and getLargestTokenAccounts
. These methods are incredibly useful but non-performant methods since they induce a heavy RPC load on Solana validator nodes, often resulting in a 5XX response due to timeout or a response with high latency.
Alchemy has built out core infrastructure that sits atop our Solana validator nodes to support these methods at scale, through what we call the AccountsDB Infrastructure. This infrastructure allows for faster, scalable, and more reliable responses to these methods by paginating the response with a pageKey
. You could then loop through your that same request with at scan and aggregate the full response from our validator nodes.
You can see pageKey
is now an optional parameter in each account-scanning method in our Solana docs, and you may also include an order
optional parameter that would sort the accounts in the response by their pubkey
field.
Here’s an example with getProgramAccounts
:
Solana Tutorials
You must not stop here! Check out the following tutorials to learn how to build with Solana: