getCompressedAccount RPC method retrieves information about a specific compressed account using either its address or hash. Information includes the compressed account state, balance, and metadata.
You can test this methods via the OpenAPI example or custom examples below.
- Checking Compressed Account Balance: Retrieve the lamport balance of any compressed account.
- Verifying Account Existence: Check if a compressed account exists and has been initialized with data or lamports.
- Inspecting Compressed Account Data: Access the stored data within a compressed account, including program-specific state.
- Identifying Account Owner: Determine which program owns a compressed account to understand how its data should be interpreted.
- Merkle Tree Information: Get the merkle tree context including leaf index and sequence number for proof generation.
address(string, optional): The base-58 encoded address of the compressed account to query.hash(string, optional): The base-58 encoded 32-byte hash of the compressed account.
address OR hash must be provided, but not both. If neither is provided, the request will fail.
Response
Returns compressed account information directly, or null if account not found:
hash(string): The 32-byte hash of the compressed account as a base-58 string.owner(string): The base-58 encoded public key of the program that owns this account.lamports(number): The number of lamports owned by the account.tree(string): The public key of the merkle tree storing this account.leafIndex(number): The leaf index of this account in the merkle tree.seq(number): The sequence number of this account.slotCreated(number): The slot when this account was created.data(object, optional): The account data object containing:discriminator(BN): The account discriminator as BN object.data(string): Base64 encoded account data.dataHash(string): The 32-byte hash of the account data.
- Address vs Hash: Use
addresswhen you know the account’s derived address, andhashwhen you have the specific hash from a previous query or transaction - Hash Format: When using the
hashparameter, pass the hash value directly as returned from other RPC methods (likegetCompressedAccountsByOwner). Hash values must be used immediately after retrieval for accurate results - Error Handling: Always check if the returned value is
nullbefore accessing account properties, as the account may not exist - Merkle Context: The returned
leafIndex,tree, andseqfields are crucial for generating merkle proofs when updating or transferring compressed accounts - Data Interpretation: The
datafield contains program-specific information. Use thediscriminatorto identify the account type and parse thedataaccordingly - Rate Limits: Be mindful of RPC rate limits when making frequent queries. Consider batching requests when possible
- Hash Verification: The
dataHashfield allows you to verify the integrity of the account data without storing the full data on-chain
Dependencies & Setup
Dependencies & Setup
Cargo.toml:TypeScript
Body
application/json
An ID to identify the request.
Available options:
test-account The version of the JSON-RPC protocol.
Available options:
2.0 The name of the method to invoke.
Available options:
getCompressedAccount Request for compressed account data
Example:
{
"address": null,
"hash": "11111111111111111111111111111111"
}