cURL
curl --request POST \
--url 'https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount' \
--header 'Content-Type: application/json' \
--data '
{
"id": "test-account",
"jsonrpc": "2.0",
"method": "getCompressedAccount",
"params": {
"address": null,
"hash": "11111111111111111111111111111111"
}
}
'import requests
url = "https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount"
payload = {
"id": "test-account",
"jsonrpc": "2.0",
"method": "getCompressedAccount",
"params": {
"address": None,
"hash": "11111111111111111111111111111111"
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 'test-account',
jsonrpc: '2.0',
method: 'getCompressedAccount',
params: {address: null, hash: '11111111111111111111111111111111'}
})
};
fetch('https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 'test-account',
'jsonrpc' => '2.0',
'method' => 'getCompressedAccount',
'params' => [
'address' => null,
'hash' => '11111111111111111111111111111111'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount"
payload := strings.NewReader("{\n \"id\": \"test-account\",\n \"jsonrpc\": \"2.0\",\n \"method\": \"getCompressedAccount\",\n \"params\": {\n \"address\": null,\n \"hash\": \"11111111111111111111111111111111\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"test-account\",\n \"jsonrpc\": \"2.0\",\n \"method\": \"getCompressedAccount\",\n \"params\": {\n \"address\": null,\n \"hash\": \"11111111111111111111111111111111\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"test-account\",\n \"jsonrpc\": \"2.0\",\n \"method\": \"getCompressedAccount\",\n \"params\": {\n \"address\": null,\n \"hash\": \"11111111111111111111111111111111\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "test-account",
"jsonrpc": "2.0",
"error": {
"code": 123,
"message": "<string>"
},
"result": {
"context": {
"slot": 100
},
"value": {
"hash": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP",
"lamports": 100,
"leafIndex": 100,
"owner": "111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj",
"slotCreated": 100,
"tree": "111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj",
"address": "111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj",
"data": {
"data": "SGVsbG8sIFdvcmxkIQ==",
"dataHash": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP",
"discriminator": 100
},
"seq": 100
}
}
}{
"error": {
"code": 123,
"message": "<string>"
},
"id": "<string>",
"jsonrpc": "<string>"
}{
"error": {
"code": 123,
"message": "<string>"
},
"id": "<string>",
"jsonrpc": "<string>"
}JSON RPC Methods
Getcompressedaccount
Retrieve compressed account information by address or hash. RPC method guide with use cases, tips and examples.
POST
/
getCompressedAccount
cURL
curl --request POST \
--url 'https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount' \
--header 'Content-Type: application/json' \
--data '
{
"id": "test-account",
"jsonrpc": "2.0",
"method": "getCompressedAccount",
"params": {
"address": null,
"hash": "11111111111111111111111111111111"
}
}
'import requests
url = "https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount"
payload = {
"id": "test-account",
"jsonrpc": "2.0",
"method": "getCompressedAccount",
"params": {
"address": None,
"hash": "11111111111111111111111111111111"
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 'test-account',
jsonrpc: '2.0',
method: 'getCompressedAccount',
params: {address: null, hash: '11111111111111111111111111111111'}
})
};
fetch('https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 'test-account',
'jsonrpc' => '2.0',
'method' => 'getCompressedAccount',
'params' => [
'address' => null,
'hash' => '11111111111111111111111111111111'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount"
payload := strings.NewReader("{\n \"id\": \"test-account\",\n \"jsonrpc\": \"2.0\",\n \"method\": \"getCompressedAccount\",\n \"params\": {\n \"address\": null,\n \"hash\": \"11111111111111111111111111111111\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"test-account\",\n \"jsonrpc\": \"2.0\",\n \"method\": \"getCompressedAccount\",\n \"params\": {\n \"address\": null,\n \"hash\": \"11111111111111111111111111111111\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://devnet.helius-rpc.com/getCompressedAccount?api-key=%3Capi_key%3E/getCompressedAccount")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"test-account\",\n \"jsonrpc\": \"2.0\",\n \"method\": \"getCompressedAccount\",\n \"params\": {\n \"address\": null,\n \"hash\": \"11111111111111111111111111111111\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "test-account",
"jsonrpc": "2.0",
"error": {
"code": 123,
"message": "<string>"
},
"result": {
"context": {
"slot": 100
},
"value": {
"hash": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP",
"lamports": 100,
"leafIndex": 100,
"owner": "111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj",
"slotCreated": 100,
"tree": "111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj",
"address": "111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj",
"data": {
"data": "SGVsbG8sIFdvcmxkIQ==",
"dataHash": "11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP",
"discriminator": 100
},
"seq": 100
}
}
}{
"error": {
"code": 123,
"message": "<string>"
},
"id": "<string>",
"jsonrpc": "<string>"
}{
"error": {
"code": 123,
"message": "<string>"
},
"id": "<string>",
"jsonrpc": "<string>"
}The
Common Use Cases
For Rust examples: Create a Cargo project with these dependencies in
Example: Fetching Compressed Account by Address
Let’s fetch information for a compressed account using its address.
Example: Fetching Compressed Account by Hash
You can also query a compressed account using its hash.
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
npm install @lightprotocol/stateless.js @solana/web3.js
Cargo.toml:[dependencies]
tokio = { version = "1.0", features = ["full"] }
anyhow = "1.0"
solana-sdk = "1.18"
# light-client = "0.1" # Add when available
serde_json = "1.0"
curl -X POST https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getCompressedAccount",
"params": {
"address": "11111113R2cuenjG5nFubqX9Wzuukdin2YfGQVzu5"
}
}'
import { Rpc, createRpc, createBN254, BN254, CompressedAccountWithMerkleContext } from '@lightprotocol/stateless.js';
async function getCompressedAccountInfo(): Promise<void> {
const rpc: Rpc = createRpc(
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY',
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY'
);
try {
// Query by address
const address: BN254 = createBN254('11111113R2cuenjG5nFubqX9Wzuukdin2YfGQVzu5', 'base58');
const accountInfo: CompressedAccountWithMerkleContext | null =
await rpc.getCompressedAccount(address);
if (!accountInfo) {
console.log('Compressed account not found.');
return;
}
console.log('Compressed Account Info:', {
hash: accountInfo.hash,
owner: accountInfo.owner,
lamports: accountInfo.lamports,
tree: accountInfo.tree,
leafIndex: accountInfo.leafIndex,
sequence: accountInfo.seq,
slotCreated: accountInfo.slotCreated,
dataHash: accountInfo.data?.dataHash,
});
} catch (error: unknown) {
console.error('Error fetching compressed account:', error);
}
}
getCompressedAccountInfo();
Rust Client:
light-client v0.14.0 is available on crates.io. Use LightClient for the current stable API.// Current API: light-client 0.14.0
use light_client::rpc::LightClient;
use solana_sdk::bs58;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
let client = LightClient::new("https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY".to_string()).await?;
// Query compressed account by address
let address = "11111113R2cuenjG5nFubqX9Wzuukdin2YfGQVzu5";
match client.get_compressed_account(Some(address), None).await? {
Some(account_info) => {
println!("Compressed Account Info:");
println!(" Hash: {}", account_info.hash);
println!(" Owner: {}", account_info.owner);
println!(" Lamports: {}", account_info.lamports);
println!(" Tree: {}", account_info.tree);
println!(" Leaf Index: {}", account_info.leaf_index);
}
None => {
println!("Compressed account not found.");
}
}
Ok(())
}
TypeScript
import { Rpc, createRpc, bn } from '@lightprotocol/stateless.js';
import { PublicKey } from '@solana/web3.js';
async function getCompressedAccountByHash(): Promise<void> {
const rpc: Rpc = createRpc(
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY',
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY'
);
try {
// First, get compressed accounts to obtain a real hash
const owner = new PublicKey('4LhEEtzAhM6wEXJR2YQHPEs79UEx8e6HncmeHbqbW1w1');
const accounts = await rpc.getCompressedAccountsByOwner(owner);
if (accounts.items.length === 0) {
console.log('No compressed accounts found');
return;
}
// Query by hash using a real hash from the first account
const hash = bn(accounts.items[0].hash);
const accountInfo = await rpc.getCompressedAccount(undefined, hash);
if (accountInfo) {
console.log('Compressed Account Info:', {
hash: accountInfo.hash,
owner: accountInfo.owner,
lamports: accountInfo.lamports,
tree: accountInfo.tree,
leafIndex: accountInfo.leafIndex
});
} else {
console.log('Compressed account not found.');
}
} catch (error: unknown) {
console.error('Error:', error);
}
}
getCompressedAccountByHash();
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
Show child attributes
Show child attributes
Example:
{
"address": null,
"hash": "11111111111111111111111111111111"
}