Overview
TheRpc class extends Solana’s Connection with compression-specific methods. It provides a unified interface for querying compressed accounts, requesting proofs, and managing state trees.
Creating an RPC Connection
Account Query Methods
getCompressedAccount
Fetch a single compressed account by hash or address.Account address (32 bytes). Provide either address or hash, not both.
Account hash. Provide either address or hash, not both.
CompressedAccountWithMerkleContext | null
The compressed account with Merkle context, or null if not found.
getMultipleCompressedAccounts
Batch fetch multiple compressed accounts.Array of account hashes to fetch.
CompressedAccountWithMerkleContext[]
Array of compressed accounts in the same order as the input hashes.
getCompressedAccountsByOwner
Get all compressed accounts owned by a public key, with optional filtering and pagination.Public key of the account owner.
Optional configuration:
filters: Array of memcmp filtersdataSlice: Limit returned data (offset + length)cursor: Pagination cursor from previous responselimit: Maximum number of accounts to return
WithCursor<CompressedAccountWithMerkleContext[]>
Object with
items array and optional cursor for pagination.Balance Methods
getCompressedBalance
Get the balance of a single compressed account.Account address. Provide either address or hash.
Account hash. Provide either address or hash.
BN
Balance in lamports.
getCompressedBalanceByOwner
Get the total compressed balance for an owner.Public key of the owner.
BN
Total balance across all compressed accounts owned by the public key.
Proof Methods
getCompressedAccountProof
Get the Merkle proof for a single account.Hash of the compressed account.
MerkleContextWithMerkleProof
Object containing:
hash: Account hashtreeInfo: Tree informationleafIndex: Position in treemerkleProof: Array of sibling hashesroot: Current rootrootIndex: Root indexproveByIndex: Whether to prove by index
getMultipleCompressedAccountProofs
Batch fetch Merkle proofs for multiple accounts.Array of account hashes.
MerkleContextWithMerkleProof[]
Array of Merkle proofs in the same order as input hashes.
getValidityProof
Request a validity proof for spending compressed accounts.Array of account hashes to spend.
Optional array of new addresses to create.
ValidityProofWithContext
Object containing:
compressedProof: ZK proof (a, b, c points)roots: Array of Merkle rootsrootIndices: Indices of rootsleafIndices: Account leaf indicesleaves: Account hashestreeInfos: Tree informationproveByIndices: Flags for proof type
getValidityProofV0
Legacy method with explicit tree specification.Array of objects with
hash, tree, and queue fields.Optional array of addresses with tree info.
Token Account Methods
getCompressedTokenAccountsByOwner
Get compressed token accounts owned by a public key.Token account owner.
Optional:
mint: Filter by mint public keycursor: Pagination cursorlimit: Maximum results
WithCursor<ParsedTokenAccount[]>
Object with
items array of token accounts and optional cursor.getCompressedTokenAccountsByDelegate
Get token accounts where the public key is a delegate.Delegate public key.
Same as
getCompressedTokenAccountsByOwner.getCompressedTokenAccountBalance
Get the token balance of a specific compressed token account.Hash of the compressed token account.
{ amount: BN }
Object containing the token amount.
getCompressedTokenBalancesByOwner
Get aggregated token balances by mint for an owner.Token owner.
Optional mint filter and pagination.
WithCursor<TokenBalance[]>
Array of
{ balance, mint } objects.getCompressedMintTokenHolders
Get all holders of a compressed mint.Mint public key.
Optional cursor and limit.
WithContext<WithCursor<CompressedMintTokenHolders[]>>
Context with slot, cursor, and array of
{ owner, balance } objects.State Tree Methods
getStateTreeInfos
Get all active state trees.TreeInfo[]
Array of state tree information objects.
selectStateTreeInfo
Utility to select an appropriate state tree.Transaction Methods
getTransactionWithCompressionInfo
Get transaction details including compression-specific info.Transaction signature (base58).
CompressedTransaction | null
Transaction with compression info:
compressionInfo.closedAccounts: Spent accountscompressionInfo.openedAccounts: Created accountstransaction: Standard Solana transaction
getCompressionSignaturesForAccount
Get all signatures for a compressed account.Account hash.
SignatureWithMetadata[]
Array of signatures with slot and blockTime.
getCompressionSignaturesForAddress
Get signatures for an account address.Account address.
Optional cursor and limit.
getCompressionSignaturesForOwner
Get all compression transactions for an owner.Owner public key.
Optional cursor and limit.
getCompressionSignaturesForTokenOwner
Get token-related signatures for an owner.Token owner.
Optional cursor and limit.
getLatestCompressionSignatures
Get the latest compression transactions.Pagination cursor.
Maximum number of signatures.
Indexer Methods
getIndexerHealth
Check indexer health status.string
Health status string (e.g., “ok”).
getIndexerSlot
Get the current indexer slot.number
Current slot number indexed.
Unified Interface Methods (V2+)
These methods provide a unified interface for both compressed and uncompressed accounts.
getAccountInfoInterface
Get account info supporting both hot (on-chain) and cold (compressed) accounts.getSignaturesForAddressInterface
Get signatures from both Solana RPC and compression indexer.getTokenAccountBalanceInterface
Get unified token balance (hot + cold).getBalanceInterface
Get unified SOL balance (hot + cold).Utility Functions
createRpc
Factory function to create an RPC connection.bn
Create a BN (big number) from various inputs.encodeBN254toBase58
Encode a BN254 field element to base58.Next Steps
Compressed Accounts
Learn about working with compressed accounts
Compressed Tokens
Build with compressed SPL tokens