Skip to main content
The RPC module provides several types for configuring requests to the Solana JSON-RPC API.

Commitment Enum

Package: software.sava.rpc.json.http.request File: Commitment.java:7 Defines the level of commitment for transaction and account queries.
public enum Commitment

Values

PROCESSED
Commitment
Query the most recent block confirmed by supermajority of the cluster as having reached maximum lockout. May still be rolled back.
CONFIRMED
Commitment
Query the most recent block that has been voted on by supermajority of the cluster. Still may be rolled back but less likely.
FINALIZED
Commitment
Query the most recent block confirmed by supermajority of the cluster as having reached maximum lockout. Cannot be rolled back.
Defined in Commitment.java:9-11.

Methods

getValue()

Get the string value for JSON-RPC requests.
String getValue()
Returns: String representation (“processed”, “confirmed”, “finalized”) Example:
Commitment commitment = Commitment.CONFIRMED;
String value = commitment.getValue();  // "confirmed"
See Commitment.java:19-21.

Usage

import software.sava.rpc.json.http.request.Commitment;

// Set default commitment on client
var client = SolanaRpcClient.build()
    .defaultCommitment(Commitment.FINALIZED)
    .createClient();

// Override per request
var accountInfo = client.getAccountInfo(
    Commitment.PROCESSED,
    publicKey
).join();
See Commitment Levels for detailed guidance.

BlockTxDetails Enum

Package: software.sava.rpc.json.http.request File: BlockTxDetails.java:3 Specifies the level of transaction detail to return when querying blocks.
public enum BlockTxDetails

Values

full
BlockTxDetails
Return full transaction details including all instructions and signatures
none
BlockTxDetails
Return no transaction details, only block metadata
signatures
BlockTxDetails
Return only transaction signatures, no instruction details
Defined in BlockTxDetails.java:5-7.

Usage

import software.sava.rpc.json.http.request.BlockTxDetails;

// Get block with full transaction details
var block = client.getBlock(
    slot,
    BlockTxDetails.full
).join();

// Get block with only signatures
var blockSigs = client.getBlock(
    Commitment.FINALIZED,
    slot,
    BlockTxDetails.signatures
).join();

// Get block metadata only (fastest)
var blockMeta = client.getBlock(
    slot,
    BlockTxDetails.none
).join();

Filter Interface

Package: software.sava.core.rpc File: Filter.java:6 Sealed interface for filtering program accounts.
public sealed interface Filter 
    permits DataSizeFilter, MemCmpFilter

Constants

MAX_MEM_COMP_LENGTH
int
default:"128"
Maximum length for memcmp filter data (128 bytes)
Defined in Filter.java:8.

Factory Methods

createDataSizeFilter()

Filter accounts by data size.
static Filter createDataSizeFilter(int dataSize)
dataSize
int
required
Required account data size in bytes
Example:
import software.sava.core.rpc.Filter;

// Filter for token accounts (165 bytes)
var filter = Filter.createDataSizeFilter(165);

var tokenAccounts = client.getProgramAccounts(
    TokenProgram.PROGRAM_ID,
    List.of(filter),
    (pubKey, data) -> TokenAccount.deserialize(data)
).join();
See Filter.java:10-12.

createMemCompFilter()

Filter accounts by comparing memory at a specific offset.
static Filter createMemCompFilter(int offset, byte[] data)
offset
int
required
Byte offset into account data
data
byte[]
required
Bytes to compare (max 128 bytes)
Example:
// Filter by specific mint
var mintFilter = Filter.createMemCompFilter(0, mintAddress.toByteArray());

var accounts = client.getProgramAccounts(
    TokenProgram.PROGRAM_ID,
    List.of(mintFilter)
).join();
See Filter.java:14-19.

createMemCompFilter() - PublicKey

Convenience method for filtering by PublicKey.
static Filter createMemCompFilter(int offset, PublicKey publicKey)
offset
int
required
Byte offset into account data
publicKey
PublicKey
required
Public key to match
Example:
// Filter token accounts by mint at offset 0
var filter = Filter.createMemCompFilter(0, tokenMint);

// Filter token accounts by owner at offset 32
var ownerFilter = Filter.createMemCompFilter(32, ownerAddress);
See Filter.java:21-23.

createMemCompFilter() - Two PublicKeys

Filter by two consecutive PublicKeys.
static Filter createMemCompFilter(
    int offset,
    PublicKey publicKey,
    PublicKey publicKey2
)
offset
int
required
Byte offset into account data
publicKey
PublicKey
required
First public key (32 bytes)
publicKey2
PublicKey
required
Second public key (32 bytes)
Example:
// Filter by two consecutive addresses
var filter = Filter.createMemCompFilter(0, address1, address2);
See Filter.java:25-30.

toJson()

Convert filter to JSON representation.
String toJson()

Filter Examples

Single Filter

import software.sava.core.rpc.Filter;
import java.util.List;

// Get all USDC token accounts
var usdcMint = PublicKey.fromBase58("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
var filter = Filter.createMemCompFilter(0, usdcMint);

var usdcAccounts = client.getProgramAccounts(
    TokenProgram.PROGRAM_ID,
    List.of(filter)
).join();

Multiple Filters

// Get USDC token accounts owned by specific address
var mintFilter = Filter.createMemCompFilter(0, usdcMint);
var ownerFilter = Filter.createMemCompFilter(32, ownerAddress);

var myUsdcAccounts = client.getProgramAccounts(
    TokenProgram.PROGRAM_ID,
    List.of(mintFilter, ownerFilter)
).join();

Size + MemCmp Filter

// Get initialized token accounts for a mint
var sizeFilter = Filter.createDataSizeFilter(165);  // Token account size
var mintFilter = Filter.createMemCompFilter(0, tokenMint);

var accounts = client.getProgramAccounts(
    TokenProgram.PROGRAM_ID,
    List.of(sizeFilter, mintFilter),
    TokenAccount.FACTORY
).join();

Custom Program Filters

// For custom program accounts
public record MyAccount(PublicKey owner, long amount) {
    // owner at offset 0 (32 bytes)
    // amount at offset 32 (8 bytes)
    
    static final BiFunction<PublicKey, byte[], MyAccount> FACTORY = 
        (pubKey, data) -> deserialize(data);
}

// Filter by owner
var ownerFilter = Filter.createMemCompFilter(0, ownerPubKey);

var myAccounts = client.getProgramAccounts(
    myProgramId,
    List.of(ownerFilter),
    MyAccount.FACTORY
).join();

ContextBoolVal

Package: software.sava.rpc.json.http.request File: ContextBoolVal.java Wraps a boolean value with RPC context information.
public record ContextBoolVal(Context context, boolean value)
Used internally for responses like transaction validity checks.

Best Practices

Commitment Selection

// For high-value transactions
var finalizedBalance = client.getBalance(
    Commitment.FINALIZED,
    treasuryAccount
).join();

// For UI updates (faster)
var currentBalance = client.getBalance(
    Commitment.CONFIRMED,
    userAccount
).join();

// For mempool monitoring
var pendingTxs = client.getSignaturesForAddress(
    Commitment.PROCESSED,
    address,
    10
).join();

Filter Optimization

// Order filters from most restrictive to least restrictive
// Size filter is fast
var sizeFilter = Filter.createDataSizeFilter(165);

// MemCmp filters are slower
var mintFilter = Filter.createMemCompFilter(0, mint);
var ownerFilter = Filter.createMemCompFilter(32, owner);

// Size first for best performance
var filters = List.of(sizeFilter, mintFilter, ownerFilter);

var accounts = client.getProgramAccounts(
    programId,
    filters
).join();

Block Query Optimization

// Get only what you need
if (needFullTransactions) {
    // Full details (slowest)
    block = client.getBlock(slot, BlockTxDetails.full).join();
} else if (needSignatures) {
    // Signatures only (faster)
    block = client.getBlock(slot, BlockTxDetails.signatures).join();
} else {
    // Metadata only (fastest)
    block = client.getBlock(slot, BlockTxDetails.none).join();
}

See Also

Build docs developers (and LLMs) love