Solana API Overview
Welcome to the Solana API Quickstart and Reference Guide. This guide provides everything you need to start building on Solana using dRPC’s JSON-RPC API. Whether you're retrieving account balances, fetching block details, executing transactions, or estimating gas fees, this comprehensive guide will help you integrate Solana seamlessly into your applications.
This page includes:
- A Quickstart Guide to help you set up and make your first Solana API request.
- A detailed list of all Solana API methods, categorized for easy reference.
To get started with building on Solana using dRPC's Solana RPC API, follow these steps:
1. Create a dRPC Account or Use Public Solana RPC Endpoints
By signing up for a free dRPC account, you can access their Premium Solana RPC endpoints.
Public endpoints:
HTTPS:
https://solana.drpc.org/
WSS:
wss://solana.drpc.org
2. Set Up Your Development Environment
RPC can be requested in various ways (opens in a new tab). In this example, we will use Node.js. Ensure you have Node.js and npm installed on your system. You can verify their installation by running:
node -v
npm -v
If not installed, download and install them from the official Node.js website.
3. Initialize Your Project
Create a new directory for your project and initialize it:
mkdir solana-drpc-quickstart
cd solana-drpc-quickstart
npm init --yes
4. Install Axios
Axios is a popular HTTP client for making API requests. Install it using npm:
npm install axios
5. Obtain dRPC Endpoint
Log in to your dRPC account and navigate to the Solana RPC endpoints section. Copy the HTTPS endpoint URL for the Solana Mainnet.
6. Write Your First Script
Create an index.js
file in your project directory and add the following code:
const axios = require('axios');
const url = 'https://lb.drpc.org/ogrpc?network=solana&dkey=YOUR_DRPC_API_KEY';
const payload = {
jsonrpc: '2.0',
id: 1,
method: 'getSlot',
params: []
};
axios.post(url, payload)
.then(response => {
console.log('The current slot is', response.data.result);
})
.catch(error => {
console.error('Error fetching slot:', error);
});
Replace https://lb.drpc.org/ogrpc?network=solana&dkey=YOUR_DRPC_API_KEY (opens in a new tab)' with the actual endpoint URL you obtained from dRPC.
- Run Your Script
Execute your script using Node.js:
node index.js
You should see the current Solana slot printed in your console.
Additional Information
dRPC offers various features such as high-performance nodes, access to multiple chains, and MEV protection. For more details, visit their Solana API documentation (opens in a new tab).
By following these steps, you can start building on Solana using dRPC's reliable and efficient RPC endpoints.
Solana API endpoints
These methods are retrieving information about blocks, accounts, or transactions, these methods provide a comprehensive way to understand the state and functioning of the network.
Accounts info#
Offers detailed information regarding the on-chain state of accounts.
getAccountInfo : Retrieves the account's data and lamports.
getBalance : Returns the balance of the specified account.
getVoteAccounts : Fetches vote accounts for the current epoch.
getLargestAccounts : Lists the largest accounts by balance.
getMultipleAccounts : Retrieves data for multiple accounts at once.
getProgramAccounts : Returns accounts associated with a specific program.
getStakeActivation : Provides activation status of a stake account.
Blocks info#
Provides detailed insights about blocks on the blockchain.
getBlockCommitment : Fetches the commitment level of a block.
getBlockProduction : Provides information on block production rates.
getBlocks : Lists blocks based on specified criteria.
getBlock : Retrieves details of a specific block.
getBlocksWithLimit : Fetches a limited number of blocks.
getBlockHeight : Returns the height of a specific block.
getBlockTime : Provides the timestamp for a block.
getConfirmedBlocks : Lists confirmed blocks in the chain.
getConfirmedBlock : Retrieves a confirmed block's details.
isBlockhashValid : Checks if a blockhash is valid.
getRecentBlockhash : Fetches the most recent blockhash.
getLatestBlockhash : Returns the latest blockhash.
Network info#
Offers aggregate data related to the overall network status and operational metrics.
getEpochInfo : Retrieves information about the current epoch.
getEpochSchedule : Provides the schedule for the current epoch.
getFeeForMessage : Returns the fee for processing a specific message.
getHighestSnapshotSlot : Fetches the highest snapshot slot in the network.
getGenesisHash : Retrieves the hash of the genesis block.
getRecentPerformanceSamples : Provides recent performance metrics for the network.
getFirstAvailableBlock : Returns the first available block in the chain.
getMinimumBalanceForRentExemption : Fetches the minimum balance required for rent exemption.
getFees : Returns the current fee structure for transactions.
getFeeCalculatorForBlockhash : Provides the fee calculator for a specific blockhash.
getRecentPrioritizationFees : Retrieves recent prioritization fees for transactions.
Subscriptions#
Allows clients to receive real-time updates and notifications about various on-chain events.
accountSubscribe : Subscribes to account updates.
accountUnsubscribe : Unsubscribes from account updates.
blockSubscribe : Subscribes to block updates.
blockUnsubscribe : Unsubscribes from block updates.
logsSubscribe : Subscribes to log updates.
logUnsubscribe : Unsubscribes from log updates.
programSubscribe : Subscribes to program updates.
programUnsubscribe : Unsubscribes from program updates.
signatureSubscribe : Subscribes to signature updates.
signatureUnsubscribe : Unsubscribes from signature updates.
slotSubscribe : Subscribes to slot updates.
slotUnsubscribe : Unsubscribes from slot updates.
Node info#
Provides data related to the configuration and health of the Solana nodes, which form the backbone of the network.
getClusterNodes : Retrieves the list of nodes in the cluster.
getHealth : Checks the health status of the node.
getVersion : Returns the version of the Solana node software.
getIdentity : Provides the node's identity information.
Slot info#
Slots represent periods of time during which a leader is responsible for processing transactions. These methods provide data related to slot timing and leadership.
getMaxRetransmitSlot : Retrieves the maximum slot for retransmission.
getMaxShredInsertSlot : Provides the maximum slot for shred insertion.
getSlot : Returns the current slot.
getSlotLeader : Fetches the leader for the current slot.
getSlotLeaders : Lists leaders for upcoming slots.
minimumLedgerSlot : Retrieves the minimum ledger slot.
getLeaderSchedule : Provides the schedule of slot leaders.
Network inflation info#
Solana implements a staking and inflation model to incentivize validators and participants. These methods help retrieve inflation-related data.
getInflationGovernor : Retrieves the inflation governor for the network.
getInflationRate : Returns the current inflation rate.
getInflationReward : Provides the inflation reward amount for validators.
getSupply : Retrieves the total supply of tokens in the network.
Token info#
Focuses on accounts and balances associated with specific tokens
getTokenSupply : Retrieves the total supply of a specific token.
getTokenAccountBalance : Returns the balance of a specific token account.
getTokenAccountsByDelegate : Lists token accounts associated with a delegate.
getTokenAccountsByOwner : Fetches token accounts owned by a specific address.
getTokenLargestAccounts : Provides a list of the largest token accounts.
requestAirdrop : Requests an airdrop of tokens to a specified account.
Transactions info#
Allows to interact with and retrieve data about specific transactions, from signatures to transaction status.
getTransactionCount : Returns the number of transactions sent from a specific address.
getConfirmedTransaction : Retrieves details of a confirmed transaction.
getTransaction : Fetches information about a transaction by its signature.
sendTransaction : Sends a transaction to the network.
simulateTransaction : Simulates the execution of a transaction.
getSignaturesForAddress : Lists signatures for transactions associated with a specific address.
getSignatureStatuses : Retrieves the statuses of transaction signatures.
getConfirmedSignaturesForAddress2 : Provides confirmed signatures for a specific address.