getAccountInfo - Solana
Example code for the getAccountInfo JSON-RPC method. Complete guide on how to use getAccountInfo JSON-RPC in GetBlock Web3 documentation.
This method returns the current state of an account, including its lamport balance, owning program, data payload, and rent epoch. This is the primary method for reading on-chain account data such as token mints, PDAs, and program-owned state.
Parameters
pubkey
string
Yes
Base58-encoded Pubkey of the account to query
config
object
No
Configuration object controlling encoding and commitment
Config Object
encoding
string
No
Data encoding: base58, base64, base64+zstd, or jsonParsed
commitment
string
No
Commitment level: processed, confirmed, or finalized. Defaults to finalized
dataSlice
object
No
Byte range to return, with offset and length fields
minContextSlot
number
No
Minimum slot the request can be evaluated at
Request
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "getAccountInfo",
"params": ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", {"encoding": "jsonParsed"}],
"id": "getblock.io"
}'const { Connection, PublicKey } = require('@solana/web3.js');
const connection = new Connection('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', 'confirmed');
const info = await connection.getParsedAccountInfo(
new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')
);
console.log(info.value);import requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'getAccountInfo',
'params': ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", {"encoding": "jsonParsed"}],
'id': 'getblock.io'
}
)
print(response.json()['result'])Response
Response Parameters
jsonrpc
string
JSON-RPC protocol version ("2.0")
id
string
Request identifier matching the request
result
object
RPC response object containing context and the account value
Value Object
lamports
number
Account balance in lamports
owner
string
Base58 Pubkey of the program that owns the account
data
array|object
Account data, encoded per the requested encoding
executable
boolean
Whether the account holds a loaded program
rentEpoch
number
Epoch at which the account next owes rent
space
number
Data length of the account in bytes
Use Cases
Token Mint Data: Read decimals, supply, and mint authority from an SPL Token mint
PDA State: Fetch program-derived account state for Anchor and native programs
Account Existence: Detect whether an associated token account has been initialized
Wallet Indexing: Resolve account owner and executable flags when classifying addresses
Partial Reads: Use dataSlice to fetch a single struct field from a large account
Error Handling
-32602
Invalid params
Malformed base58 Pubkey, unsupported encoding, or invalid dataSlice range
-32603
Internal error
Node failed to read the account from its accounts database
-32016
Minimum context slot has not been reached
The node has not yet processed minContextSlot
-32005
Node is unhealthy
The node has fallen behind the cluster tip and cannot serve account state
-32601
Method not found
Encoding requested is not supported by the node build
Last updated
Was this helpful?