getTransactionWithCompressionInfo
Retrieve the transaction data for the transaction with the given signature along with parsed compression info. RPC method guide with use cases, tips and examples.
ThegetTransactionWithCompressionInfo
RPC method returns transaction data along with compression information showing which compressed accounts were opened (created) and closed (consumed) during the transaction. This method helps with transaction analysis, account lifecycle tracking, and debugging of compression operations.
An ID to identify the request.
The version of the JSON-RPC protocol.
The name of the method to invoke.
Invalid request.
Unauthorized request.
Request was forbidden.
The specified resource was not found.
Exceeded rate limit.
The server encountered an unexpected condition that prevented it from fulfilling the request.
POST / HTTP/1.1
Host: mainnet.helius-rpc.com
Content-Type: application/json
Accept: */*
Content-Length: 152
{
"id": "test-account",
"jsonrpc": "2.0",
"method": "getTransactionWithCompressionInfo",
"params": {
"signature": "5J8H5sTvEhnGcB4R8K1n7mfoiWUD9RzPVGES7e3WxC7c"
}
}
{
"compression_info": {
"closed_accounts": [],
"opened_accounts": []
},
"transaction": {}
}
Common Use Cases
Transaction Analysis: Understand what compressed accounts were affected by a transaction
Account Lifecycle Tracking: Monitor when compressed accounts are created and consumed
Debugging: Identify which accounts changed during failed or unexpected transactions
Audit Trails: Track compressed account state changes for compliance
Parameters
signature
(string, required): Base58-encoded transaction signature to query compression information for.
Note: Only transactions involving compressed accounts will return compression data. Regular Solana transactions return null.
Response
The response contains compression information and transaction data, or null if transaction not found:
compressionInfo
(object): Contains details about compressed account changesclosedAccounts
(array): Compressed accounts consumed (spent) in this transactionaccount
(object): Complete compressed account data with merkle contextmaybeTokenData
(object | null): Token data if this is a compressed token account
openedAccounts
(array): New compressed accounts created in this transactionaccount
(object): Complete compressed account data with merkle contextmaybeTokenData
(object | null): Token data if this is a compressed token account
preTokenBalances
(array, optional): Token balances before transactionowner
(PublicKey): Public key of token account ownermint
(PublicKey): Public key of token mintamount
(BN): Token amount as BN object
postTokenBalances
(array, optional): Token balances after transactionowner
(PublicKey): Public key of token account ownermint
(PublicKey): Public key of token mintamount
(BN): Token amount as BN object
transaction
(object): Standard Solana transaction data
Developer Tips
Compression-only: This method only works with transactions that involve compressed accounts
Real signatures required: Use actual transaction signatures from compression operations
Account lifecycle: opened = created, closed = consumed/spent in the transaction
Token data: maybeTokenData is null for regular compressed accounts, populated for token accounts
Balance tracking: Use pre/postTokenBalances for detailed token amount changes
State analysis: Compare opened vs closed accounts to understand transaction effects
Troubleshooting
Examples
The below examples work - just make sure you installed the dependencies.
Example: Analyze Transaction
import { createRpc, Rpc, CompressedTransaction } from '@lightprotocol/stateless.js';
const rpc: Rpc = createRpc(
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY',
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY'
);
async function analyzeTransactionCompression(): Promise<void> {
const signature: string = 'TRANSACTION_SIGNATURE_HERE';
const result: CompressedTransaction | null =
await rpc.getTransactionWithCompressionInfo(signature);
if (!result) {
console.log('Transaction not found or has no compression info');
return;
}
const { compressionInfo } = result;
console.log('Transaction Compression Summary:', {
openedCount: compressionInfo.openedAccounts.length,
closedCount: compressionInfo.closedAccounts.length,
hasTokenBalances: !!(compressionInfo.preTokenBalances || compressionInfo.postTokenBalances)
});
// Type-safe account analysis
compressionInfo.closedAccounts.forEach((entry, index) => {
console.log(`Closed Account ${index + 1}:`, {
hash: entry.account.hash.toString(),
lamports: entry.account.lamports.toString(),
hasTokenData: !!entry.maybeTokenData
});
});
compressionInfo.openedAccounts.forEach((entry, index) => {
console.log(`Opened Account ${index + 1}:`, {
hash: entry.account.hash.toString(),
lamports: entry.account.lamports.toString(),
hasTokenData: !!entry.maybeTokenData
});
});
}
analyzeTransactionCompression();
Example: Track Token Balance Changes
async function trackTokenBalanceChanges(): Promise<void> {
const connection = createRpc(
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY',
'https://devnet.helius-rpc.com/?api-key=YOUR_API_KEY'
);
const signature = 'TOKEN_TRANSACTION_SIGNATURE_HERE';
const result = await connection.getTransactionWithCompressionInfo(signature);
if (!result) {
console.log('Transaction not found');
return;
}
const { compressionInfo } = result;
// Analyze token balance changes if available
if (compressionInfo.preTokenBalances && compressionInfo.postTokenBalances) {
console.log('Token Balance Changes:');
compressionInfo.preTokenBalances.forEach((preBalance, index) => {
const postBalance = compressionInfo.postTokenBalances![index];
const change = postBalance.amount.sub(preBalance.amount);
if (!change.isZero()) {
console.log(` Owner: ${preBalance.owner.toBase58()}`);
console.log(` Mint: ${preBalance.mint.toBase58()}`);
console.log(` Change: ${change.toString()}`);
}
});
} else {
console.log('No token balance data available for this transaction');
}
// Analyze token accounts in opened/closed arrays
const tokenAccountsOpened = compressionInfo.openedAccounts.filter(
entry => entry.maybeTokenData !== null
);
const tokenAccountsClosed = compressionInfo.closedAccounts.filter(
entry => entry.maybeTokenData !== null
);
console.log(`Token accounts opened: ${tokenAccountsOpened.length}`);
console.log(`Token accounts closed: ${tokenAccountsClosed.length}`);
return {
tokenAccountsOpened: tokenAccountsOpened.length,
tokenAccountsClosed: tokenAccountsClosed.length
};
}
trackTokenBalanceChanges();
Last updated