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);
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
Last updated