Solana — Methods (1/4)
API reference for Solana. All methods ->
getAccountInfo
Returns all information associated with the account of provided Pubkey.
Parameters
-
id(integer; required): a request ID (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request. -
params(array; required):<string>: pubkey of account to query, as base-58 encoded string.<object>(optional): configuration object containing the following fields:commitment(string): 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. 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: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.
encoding(string): encoding for Account data, either "base58" (slow), "base64", "base64+zstd", or "jsonParsed". "base58" is limited to Account data of less than 129 bytes. "base64" will return base64 encoded data for Account data of any size. "base64+zstd" compresses the Account data using Zstandard and base64-encodes the result. "jsonParsed" encoding attempts to use program-specific state parsers to return more human-readable and explicit account state data. If "jsonParsed" is requested but a parser cannot be found, the field falls back to "base64" encoding, detectable when thedatafield is typestring.dataSlice(object): limit the returned account data using the providedoffset: <usize>andlength: <usize>fields; only available for "base58", "base64" or "base64+zstd" encodings.minContextSlot(number): sets the minimum slot that the request can be evaluated at.
Returns
<null>: if the requested account doesn't exist.<object>: otherwise a JSON object containing:lamports(u64): number of lamports assigned to this account, as a u64.owner(string): base-58 encoded Pubkey of the program this account has been assigned to.data([string, encoding]|object): data associated with the account, either as encoded binary data or JSON format{<program>: <state>}, depending on the encoding parameter.executable(boolean): boolean indicating if the account contains a program (and is strictly read-only).rentEpoch(u64): the epoch at which this account will next owe rent, as u64.
Request example 1
curl -X POST https://rpc.ankr.com/solana/YOUR_ANKR_API_KEY \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "getAccountInfo",
"params": [
"vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg",
{
"encoding": "base58"
}
],
"id": 1
}'
Response example 1
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"context": {
"apiVersion": "2.2.3",
"slot": 374431575
},
"value": {
"data": [
"",
"base58"
],
"executable": false,
"lamports": 88860054690252,
"owner": "11111111111111111111111111111111",
"rentEpoch": 18446744073709551615,
"space": 0
}
}
}
Request example 2
curl -X POST https://rpc.ankr.com/solana/YOUR_ANKR_API_KEY \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "getAccountInfo",
"params": [
"4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA",
{
"encoding": "jsonParsed"
}
],
"id": 1
}'
Response example 2
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"context": {
"apiVersion": "2.2.3",
"slot": 374431699
},
"value": {
"data": [
"",
"base64"
],
"executable": false,
"lamports": 7998763451,
"owner": "2WRuhE4GJFoE23DYzp2ij6ZnuQ8p9mJeU6gDgfsjR4or",
"rentEpoch": 18446744073709551615,
"space": 0
}
}
}
getBalance
Returns the balance of the account of provided Pubkey.
Parameters
-
id(integer; required): a request ID (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request. -
params(array; required):-
<string>: pubkey of account to query, as base-58 encoded string. -
<object>: configuration object containing the following fields:commitment(string; optional): 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. 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: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.
minContextSlot(number; optional): sets the minimum slot that the request can be evaluated at.
-
Returns
value(u64): an account balance.
Request example
curl -X POST https://rpc.ankr.com/solana/YOUR_ANKR_API_KEY \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "getBalance",
"params": [
"4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA"
],
"id": 1
}'
Response example
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"context": {
"apiVersion": "2.2.3",
"slot": 374431850
},
"value": 7998763451
}
}
getBlock
Returns identity and transaction information about a confirmed block in the ledger.
Parameters
-
id(integer; required): a request ID (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request. -
params(array; required):<u64>: slot, as a u64 integer.<object>(optional): configuration object containing the following optional fields:encoding(string): encoding for each returned Transaction, either "json", "jsonParsed", "base58" (slow), "base64". If parameter not provided, the default encoding is "json". "jsonParsed" encoding attempts to use program-specific instruction parsers to return more human-readable and explicit data in thetransaction.message.instructionslist. If "jsonParsed" is requested but a parser cannot be found, the instruction falls back to regular JSON encoding (accounts,data, andprogramIdIndexfields).transactionDetails(string): level of transaction detail to return, either "full", "accounts", "signatures", or "none". If parameter not provided, the default detail level is "full". If "accounts" are requested, transaction details only include signatures and an annotated list of accounts in each transaction. Transaction metadata is limited to only: fee, err, pre_balances, post_balances, pre_token_balances, and post_token_balances.rewards(boolean): whether to populate therewardsarray. If parameter not provided, the default includes rewards.commitment(string; default: "finalized"): 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. 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: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.
maxSupportedTransactionVersion(number): sets the max transaction version to return in responses. If the requested block contains a transaction with a higher version, an error will be returned. If this parameter is omitted, only legacy transactions will be returned, and a block containing any versioned transaction will prompt the error.
Returns
<null>: if specified block is not confirmed.<object>: if block is confirmed, an object with the following fields:blockhash(string): the blockhash of this block, as base-58 encoded string.previousBlockhash(string): the blockhash of this block's parent, as base-58 encoded string; if the parent block is not available due to ledger cleanup, this field will return "11111111111111111111111111111111".parentSlot(u64): the slot index of this block's parent.transactions(array): to be included if "full" transaction details are requested; an array of JSON objects containing:transaction(object|[string,encoding]): a transaction object, either in JSON format or encoded binary data, depending on encoding parameter.meta(object): a transaction status metadata object, containingnullor:err(object|null): an error if transaction failed, null if transaction succeeded. TransactionError definitions.fee(u64): a fee this transaction was charged with, as u64 integer.preBalances(array): an array of u64 account balances from before the transaction was processed.postBalances(array): an array of u64 account balances after the transaction was processed.innerInstructions(array|null): the list of inner instructions or null if inner instruction recording was not enabled during this transaction.preTokenBalances(array|undefined): the list of token balances from before the transaction was processed or omitted if token balance recording was not yet enabled during this transaction.postTokenBalances(array|undefined): the list of token balances from after the transaction was processed or omitted if token balance recording was not yet enabled during this transaction.logMessages(array|null): an array of string log messages ornullif log message recording was not enabled during this transaction.rewards(array|null): transaction-level rewards, populated if rewards are requested; an array of JSON objects containing:pubkey(string): the public key, as base-58 encoded string, of the account that received the reward.lamports(i64): the number of reward lamports credited or debited by the account, as an i64.postBalance(u64): an account balance in lamports after the reward was applied.rewardType(string|undefined): the type of reward: "fee", "rent", "voting", "staking".commission(u8|undefined): a vote account commission when the reward was credited, only present for voting and staking rewards.
- [DEPRECATED]
status(object): a transaction status:"Ok": <null>: a transaction was successful."Err": <ERR>: a transaction failed with TransactionError.
loadedAddresses(object|undefined): transaction addresses loaded from address lookup tables. Undefined ifmaxSupportedTransactionVersionis not set in request params:writable(array[string]): an ordered list of base-58 encoded addresses for writable loaded accounts.readonly(array[string]): an ordered list of base-58 encoded addresses for readonly loaded accounts.
returnData(object|undefined): the most-recent return data generated by an instruction in the transaction, with the following fields:programId(string): the program that generated the return data, as base-58 encoded Pubkey.data(string, encoding): the return data itself, as base-64 encoded binary data.
computeUnitsConsumed(u64|undefined): the number of compute units consumed by the transaction.
version("legacy"|number|undefined): a transaction version; undefined ifmaxSupportedTransactionVersionis not set in request params.
signatures(array): to be included if "signatures" are requested for transaction details; an array of signatures strings, corresponding to the transaction order in the block.rewards(array|undefined): block-level rewards, present if rewards are requested; an array of JSON objects containing:pubkey(string): the public key, as base-58 encoded string, of the account that received the reward.lamports(i64): the number of reward lamports credited or debited by the account, as an i64.postBalance(u64): an account balance in lamports after the reward was applied.rewardType(string|undefined): the type of reward: "fee", "rent", "voting", "staking".commission(u8|undefined): the vote account commission when the reward was credited, included for voting and staking rewards only.
blockTime(i64|null): estimated production time, as Unix timestamp (seconds since the Unix epoch). null if not available.blockHeight(u64|null): the number of blocks beneath this block.
Request example 1
curl -X POST https://rpc.ankr.com/solana/YOUR_ANKR_API_KEY \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "getBlock",
"params": [370774640, {"encoding": "json","maxSupportedTransactionVersion":0,"transactionDetails":"full","rewards":false}],
"id": 1
}'
Response example 1
{
"jsonrpc": "2.0",
"result": {
"blockHeight": 358752908,
"blockTime": 1743307608,
"blockhash": "HF4FCaWTHZqoTSqeZS5xtqfvKB3crSHgqugWCC2CrF6N",
"parentSlot": 370774639,
"previousBlockhash": "2f1r7z58nr7HX92YDko28wAHTyWAHYvmDHfVjSApvw7T",
"transactions": [
{
"meta": {
"computeUnitsConsumed": 150,
"err": null,
"fee": 5000,
"innerInstructions": [],
"loadedAddresses": {
"readonly": [],
"writable": []
},
"logMessages": [
"Program 11111111111111111111111111111111 invoke [1]",
"Program 11111111111111111111111111111111 success"
],
"postBalances": [
10804309975,
10804407530,
1
],
"postTokenBalances": [],
"preBalances": [
10804315088,
10804407417,
1
],
"preTokenBalances": [],
"rewards": null,
"status": {
"Ok": null
}
},
"transaction": {
"message": {
"accountKeys": [
"ANVUJaJoVaJZELtV2AvRp7V5qPV1B84o29zAwDhPj1c2",
"4PkiqJkUvxr9P8C1UsMqGN8NJsUcep9GahDRLfmeu8UK",
"11111111111111111111111111111111"
],
"header": {
"numReadonlySignedAccounts": 0,
"numReadonlyUnsignedAccounts": 1,
"numRequiredSignatures": 1
},
"instructions": [
{
"accounts": [
0,
1
],
"data": "3Bxs4KkuG3n7y751",
"programIdIndex": 2,
"stackHeight": null
}
],
"recentBlockhash": "2XvJSKxQXyiYzdVdWQ3hQkb7FZMRnevWUtyttLCtweha"
},
"signatures": [
"32wUcJEURNhdDJve1y7giwE1zhMWRgGbNwfn3cxsLmtTznnunGEbvDjkispJCVnu7XfTmHreeLfRDpETgzczMG8B"
]
},
"version": "legacy"
}
]
},
"id": 1
}
Request example 2
curl -X POST https://rpc.ankr.com/solana/YOUR_ANKR_API_KEY \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "getBlock",
"params": [370774640, "base64"],
"id": 1
}'
Response example 2
{
"jsonrpc": "2.0",
"result": {
"blockHeight": 358752908,
"blockTime": 1743307608,
"blockhash": "HF4FCaWTHZqoTSqeZS5xtqfvKB3crSHgqugWCC2CrF6N",
"parentSlot": 370774639,
"previousBlockhash": "2f1r7z58nr7HX92YDko28wAHTyWAHYvmDHfVjSApvw7T",
"rewards": [
{
"commission": null,
"lamports": 77800,
"postBalance": 1012068020241072,
"pubkey": "dv2eQHeP4RFrJZ6UeiZWoc3XTtmtZCUKxxCApCDcRNV",
"rewardType": "Fee"
}
],
"transactions": [
{
"meta": {
"computeUnitsConsumed": 150,
"err": null,
"fee": 5000,
"innerInstructions": [],
"loadedAddresses": {
"readonly": [],
"writable": []
},
"logMessages": [
"Program 11111111111111111111111111111111 invoke [1]",
"Program 11111111111111111111111111111111 success"
],
"postBalances": [
10804309975,
10804407530,
1
],
"postTokenBalances": [],
"preBalances": [
10804315088,
10804407417,
1
],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
},
"transaction": [
"AWW00bg6XvEKFL0bfYFKxozs1lqn2iXsNGSISW8ecRprGyocrjVocrAFanSZbvhHxCtlHHELDHJQwMzkvi7AtQwBAAEDizqSQJGZ3Exs17wQBP+BB3AlC5LWj0lppkJp/w/nr98yZ0Y8gaZ3Klk/NF/WDYIThTzpRp42PYFbnRVVqliKHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFsdg39g9WrKEsn+BDMcD8H/kmr6+KwxKnn0feVGtoSUBAgIAAQwCAAAAcQAAAAAAAAA=",
"base64"
]
}
]
},
"id": 1
}