JSON RPC methods
Overview of all available ZK compression JSON RPC endpoints on Solana, best practices, and error codes.
Interact with compressed accounts directly with the ZK Compression JSON RPC API. It's a thin wrapper extending Solana's web3.js Connection class with compression-related endpoints.
The API exposed by the indexer closely mirrors existing RPC calls, with one-to-one mapping:
getAccountInfo
getCompressedAccount
getBalance
getCompressedBalance
getTokenAccountsByOwner
getCompressedTokenAccountsByOwner
getProgramAccounts
getCompressedAccountsByOwner
Creating an RPC Connection
Connect to a specific RPC endpoint
import {
Rpc,
createRpc,
} from "@lightprotocol/stateless.js";
// Helius exposes Solana and Photon RPC endpoints through a single URL
const RPC_ENDPOINT = "https://mainnet.helius-rpc.com?api-key=<api_key>";
const PHOTON_ENDPOINT = RPC_ENDPOINT;
const PROVER_ENDPOINT = RPC_ENDPOINT;
const connection: Rpc = createRpc(RPC_ENDPOINT, PHOTON_ENDPOINT, PROVER_ENDPOINT)
console.log("connection", connection);import {
Rpc,
createRpc,
} from "@lightprotocol/stateless.js";
// Helius exposes Solana and Photon RPC endpoints through a single URL
const RPC_ENDPOINT = "https://devnet.helius-rpc.com?api-key=<api_key>";
const PHOTON_ENDPOINT = RPC_ENDPOINT;
const PROVER_ENDPOINT = RPC_ENDPOINT;
const connection: Rpc = createRpc(RPC_ENDPOINT, PHOTON_ENDPOINT, PROVER_ENDPOINT)
console.log("connection", connection);Best Practices
Commitment Levels
Use appropriate commitment levels: processed(fastest), confirmed (balanced), finalized (most reliable)
Rate Limiting
Implement retry logic and respect rate limits. Public endpoints: 100 req/s, Private: 1000+ req/s
Batch Requests
Use batch requests when possible to improve efficiency and reduce API calls
Caching
Cache frequently accessed data to reduce API calls and improve performance
Error Codes
-32600
Invalid Request
The JSON sent is not a valid Request object
-32601
Method not found
The method does not exist / is not available
-32602
Invalid params
Invalid method parameter(s)
-32603
Internal error
Internal JSON-RPC error
-32000
Account not found
The compressed account was not found
-32001
Invalid account hash
The provided account hash is invalid
Mainnet ZK Compression JSON RPC Methods
GetCompressedAccount
Retrieves information about a specific compressed account by its address or hash.
GetCompressedTokenAccountsByDelegate
Returns all compressed token accounts delegated to a specific address.
GetCompressedTokenBalancesByOwner
Retrieves all token balances for compressed accounts owned by an address.
GetCompressionSignaturesForAccount
Returns signatures for transactions involving a compressed account.
GetCompressionSignaturesForAddress
Retrieves signatures for transactions involving a specific address.
GetCompressionSignaturesForTokenOwner
Lists signatures for transactions involving tokens owned by an address.
GetLatestCompressionSignatures
Returns the most recent transaction signatures related to compression.
GetMultipleNewAddressProofs
Returns proofs that the new addresses are not taken already and can be created.
Last updated
Was this helpful?