13 KiB
title | displayed_sidebar | hide_table_of_contents |
---|---|---|
JSON RPC HTTP Methods | apiHttpMethodsSidebar | true |
Solana nodes accept HTTP requests using the JSON-RPC 2.0 specification.
:::info For JavaScript applications, use the @solana/web3.js library as a convenient interface for the RPC methods to interact with a Solana node.
For an PubSub connection to a Solana node, use the Websocket API. :::
RPC HTTP Endpoint
Default port: 8899 e.g. http://localhost:8899, http://192.168.1.88:8899
Request Formatting
To make a JSON-RPC request, send an HTTP POST request with a Content-Type: application/json
header. The JSON request data should contain 4 fields:
jsonrpc: <string>
- set to"2.0"
id: <number>
- a unique client-generated identifying integermethod: <string>
- a string containing the method to be invokedparams: <array>
- a JSON array of ordered parameter values
Example using curl:
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
]
}
'
The response output will be a JSON object with the following fields:
jsonrpc: <string>
- matching the request specificationid: <number>
- matching the request identifierresult: <array|number|object|string>
- requested data or success confirmation
Requests can be sent in batches by sending an array of JSON-RPC request objects as the data for a single POST.
Definitions
- Hash: A SHA-256 hash of a chunk of data.
- Pubkey: The public key of a Ed25519 key-pair.
- Transaction: A list of Solana instructions signed by a client keypair to authorize those actions.
- Signature: An Ed25519 signature of transaction's payload data including instructions. This can be used to identify transactions.
Configuring State Commitment
For preflight checks and transaction processing, Solana nodes choose which bank state to query based on a commitment requirement set by the client. The commitment describes how finalized a block is at that point in time. When querying the ledger state, it's recommended to use lower levels of commitment to report progress and higher levels to ensure the state will not be rolled back.
In descending order of commitment (most finalized to least finalized), clients may specify:
"finalized"
- the node will query the most recent block confirmed by supermajority of the cluster as having reached maximum lockout, meaning the cluster has recognized this block as finalized"confirmed"
- the node will query the most recent block that has been voted on by supermajority of the cluster.- It incorporates votes from gossip and replay.
- It does not count votes on descendants of a block, only direct votes on that block.
- This confirmation level also upholds "optimistic confirmation" guarantees in release 1.3 and onwards.
"processed"
- the node will query its most recent block. Note that the block may still be skipped by the cluster.
For processing many dependent transactions in series, it's recommended to use
"confirmed"
commitment, which balances speed with rollback safety.
For total safety, it's recommended to use"finalized"
commitment.
Example
The commitment parameter should be included as the last element in the params
array:
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri",
{
"commitment": "finalized"
}
]
}
'
Default:
If commitment configuration is not provided, the node will default to "finalized"
commitment
Only methods that query bank state accept the commitment parameter. They are indicated in the API Reference below.
RpcResponse Structure
Many methods that take a commitment parameter return an RpcResponse JSON object comprised of two parts:
context
: An RpcResponseContext JSON structure including aslot
field at which the operation was evaluated.value
: The value returned by the operation itself.
Parsed Responses
Some methods support an encoding
parameter, and can return account or
instruction data in parsed JSON format if "encoding":"jsonParsed"
is requested
and the node has a parser for the owning program. Solana nodes currently support
JSON parsing for the following native and SPL programs:
Program | Account State | Instructions |
---|---|---|
Address Lookup | v1.15.0 | v1.15.0 |
BPF Loader | n/a | stable |
BPF Upgradeable Loader | stable | stable |
Config | stable | |
SPL Associated Token Account | n/a | stable |
SPL Memo | n/a | stable |
SPL Token | stable | stable |
SPL Token 2022 | stable | stable |
Stake | stable | stable |
Vote | stable | stable |
The list of account parsers can be found here, and instruction parsers here.
Filter criteria
Some methods support providing a filters
object to enable pre-filtering the data returned within the RpcResponse JSON object. The following filters exist:
-
memcmp: object
- compares a provided series of bytes with program account data at a particular offset. Fields:offset: usize
- offset into program account data to start comparisonbytes: string
- data to match, as encoded stringencoding: string
- encoding for filterbytes
data, either "base58" or "base64". Data is limited in size to 128 or fewer decoded bytes.
NEW: This field, and base64 support generally, is only available in solana-core v1.14.0 or newer. Please omit when querying nodes on earlier versions
-
dataSize: u64
- compares the program account data length with the provided data size
Health Check
Although not a JSON RPC API, a GET /health
at the RPC HTTP Endpoint provides a
health-check mechanism for use by load balancers or other network
infrastructure. This request will always return a HTTP 200 OK response with a body of
"ok", "behind" or "unknown":
ok
: The node is withinHEALTH_CHECK_SLOT_DISTANCE
slots from the latest cluster confirmed slotbehind { distance }
: The node is behinddistance
slots from the latest cluster confirmed slot wheredistance > HEALTH_CHECK_SLOT_DISTANCE
unknown
: The node is unable to determine where it stands in relation to the cluster
JSON RPC API Reference
import GetAccountInfo from "./methods/_getAccountInfo.mdx"
import GetBalance from "./methods/_getBalance.mdx"
import GetBlock from "./methods/_getBlock.mdx"
import GetBlockHeight from "./methods/_getBlockHeight.mdx"
import GetBlockProduction from "./methods/_getBlockProduction.mdx"
import GetBlockCommitment from "./methods/_getBlockCommitment.mdx"
import GetBlocks from "./methods/_getBlocks.mdx"
import GetBlocksWithLimit from "./methods/_getBlocksWithLimit.mdx"
import GetBlockTime from "./methods/_getBlockTime.mdx"
import GetClusterNodes from "./methods/_getClusterNodes.mdx"
import GetEpochInfo from "./methods/_getEpochInfo.mdx"
import GetEpochSchedule from "./methods/_getEpochSchedule.mdx"
import GetFeeForMessage from "./methods/_getFeeForMessage.mdx"
import GetFirstAvailableBlock from "./methods/_getFirstAvailableBlock.mdx"
import GetGenesisHash from "./methods/_getGenesisHash.mdx"
import GetHealth from "./methods/_getHealth.mdx"
import GetHighestSnapshotSlot from "./methods/_getHighestSnapshotSlot.mdx"
import GetIdentity from "./methods/_getIdentity.mdx"
import GetInflationGovernor from "./methods/_getInflationGovernor.mdx"
import GetInflationRate from "./methods/_getInflationRate.mdx"
import GetInflationReward from "./methods/_getInflationReward.mdx"
import GetLargestAccounts from "./methods/_getLargestAccounts.mdx"
import GetLatestBlockhash from "./methods/_getLatestBlockhash.mdx"
import GetLeaderSchedule from "./methods/_getLeaderSchedule.mdx"
import GetMaxRetransmitSlot from "./methods/_getMaxRetransmitSlot.mdx"
import GetMaxShredInsertSlot from "./methods/_getMaxShredInsertSlot.mdx"
import GetMinimumBalanceForRentExemption from "./methods/_getMinimumBalanceForRentExemption.mdx"
import GetMultipleAccounts from "./methods/_getMultipleAccounts.mdx"
import GetProgramAccounts from "./methods/_getProgramAccounts.mdx"
import GetRecentPerformanceSamples from "./methods/_getRecentPerformanceSamples.mdx"
import GetRecentPrioritizationFees from "./methods/_getRecentPrioritizationFees.mdx"
import GetSignaturesForAddress from "./methods/_getSignaturesForAddress.mdx"
import GetSignatureStatuses from "./methods/_getSignatureStatuses.mdx"
import GetSlot from "./methods/_getSlot.mdx"
import GetSlotLeader from "./methods/_getSlotLeader.mdx"
import GetSlotLeaders from "./methods/_getSlotLeaders.mdx"
import GetStakeActivation from "./methods/_getStakeActivation.mdx"
import GetStakeMinimumDelegation from "./methods/_getStakeMinimumDelegation.mdx"
import GetSupply from "./methods/_getSupply.mdx"
import GetTokenAccountBalance from "./methods/_getTokenAccountBalance.mdx"
import GetTokenAccountsByDelegate from "./methods/_getTokenAccountsByDelegate.mdx"
import GetTokenAccountsByOwner from "./methods/_getTokenAccountsByOwner.mdx"
import GetTokenLargestAccounts from "./methods/_getTokenLargestAccounts.mdx"
import GetTokenSupply from "./methods/_getTokenSupply.mdx"
import GetTransaction from "./methods/_getTransaction.mdx"
import GetTransactionCount from "./methods/_getTransactionCount.mdx"
import GetVersion from "./methods/_getVersion.mdx"
import GetVoteAccounts from "./methods/_getVoteAccounts.mdx"
import IsBlockhashValid from "./methods/_isBlockhashValid.mdx"
import MinimumLedgerSlot from "./methods/_minimumLedgerSlot.mdx"
import RequestAirdrop from "./methods/_requestAirdrop.mdx"
import SendTransaction from "./methods/_sendTransaction.mdx"
import SimulateTransaction from "./methods/_simulateTransaction.mdx"
JSON RPC API Deprecated Methods
import GetConfirmedBlock from "./deprecated/_getConfirmedBlock.mdx"
import GetConfirmedBlocks from "./deprecated/_getConfirmedBlocks.mdx"
import GetConfirmedBlocksWithLimit from "./deprecated/_getConfirmedBlocksWithLimit.mdx"
import GetConfirmedSignaturesForAddress2 from "./deprecated/_getConfirmedSignaturesForAddress2.mdx"
import GetConfirmedTransaction from "./deprecated/_getConfirmedTransaction.mdx"
import GetFeeCalculatorForBlockhash from "./deprecated/_getFeeCalculatorForBlockhash.mdx"
import GetFeeRateGovernor from "./deprecated/_getFeeRateGovernor.mdx"
import GetFees from "./deprecated/_getFees.mdx"
import GetRecentBlockhash from "./deprecated/_getRecentBlockhash.mdx"
import GetSnapshotSlot from "./deprecated/_getSnapshotSlot.mdx"