Parameters

config
object

Configuration object containing:

commitment
string

Commitment level (processed, confirmed, finalized)

Response

result
number

The current transaction count

Code Examples

Basic Request

curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTransactionCount"
}'

Using web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://rpc.orbitflare.com');

// Get transaction count
const count = await connection.getTransactionCount();
console.log('Transaction count:', count);

// Get transaction count with analysis
async function getTransactionCountWithAnalysis(
  config: { commitment?: string }
) {
  const count = await connection.getTransactionCount(config);
  
  return {
    count,
    analysis: {
      timestamp: Date.now(),
      commitment: config.commitment
    }
  };
}

Notes

  1. Returns the current transaction count from the ledger
  2. The count includes all transactions processed by the node
  3. The response is immediate as it reads from the current state
  4. The count can change with new transactions
  5. The count may vary between nodes due to network propagation

Best Practices

  1. Use appropriate commitment level based on your needs
  2. Cache results when appropriate to reduce RPC load
  3. Monitor for changes in transaction count
  4. Consider using websocket subscription for real-time updates
  5. Handle network errors and retry when appropriate

Common Errors

CodeMessageSolution
-32601Method not foundVerify you’re connected to a Solana RPC node
-32602Invalid paramsCheck configuration parameters

Use Cases

  1. Transaction Count Analysis

    interface TransactionCountAnalysis {
      count: number;
      metrics: {
        timestamp: number;
        commitment?: string;
      };
    }
    
    class TransactionCountAnalyzer {
      async analyzeTransactionCount(
        config: { commitment?: string }
      ): Promise<TransactionCountAnalysis> {
        const count = await connection.getTransactionCount(config);
        
        return {
          count,
          metrics: {
            timestamp: Date.now(),
            commitment: config.commitment
          }
        };
      }
    }
    
  2. Transaction Count Monitoring

    interface TransactionCountChange {
      changes: {
        previousCount: number;
        currentCount: number;
        difference: number;
        percentageChange: number;
      };
      metadata: {
        timestamp: number;
      };
    }
    
    class TransactionCountMonitor {
      private previousCount: number | null = null;
      
      async monitorTransactionCount(
        config: { commitment?: string }
      ): Promise<TransactionCountChange | null> {
        const currentCount = await connection.getTransactionCount(config);
        
        if (this.previousCount !== null && this.previousCount !== currentCount) {
          const difference = currentCount - this.previousCount;
          const percentageChange = (difference / this.previousCount) * 100;
          
          this.previousCount = currentCount;
          
          return {
            changes: {
              previousCount: this.previousCount,
              currentCount,
              difference,
              percentageChange
            },
            metadata: {
              timestamp: Date.now()
            }
          };
        }
        
        this.previousCount = currentCount;
        return null;
      }
    }
    
  3. Transaction Count Planning

    interface TransactionCountPlan {
      currentCount: number;
      recommendations: Array<{
        type: 'scale' | 'optimize' | 'monitor';
        reason: string;
      }>;
      metadata: {
        timestamp: number;
      };
    }
    
    class TransactionCountPlanner {
      private readonly maxTransactionsPerSecond = 1000;
      private readonly minTransactionsPerSecond = 100;
      
      async planTransactionCount(
        config: { commitment?: string }
      ): Promise<TransactionCountPlan> {
        const currentCount = await connection.getTransactionCount(config);
        
        const recommendations: Array<{
          type: 'scale' | 'optimize' | 'monitor';
          reason: string;
        }> = [];
        
        // Check for high transaction rate
        if (currentCount > this.maxTransactionsPerSecond) {
          recommendations.push({
            type: 'scale',
            reason: `Transaction count (${currentCount}) exceeds maximum (${this.maxTransactionsPerSecond})`
          });
        }
        
        // Check for low transaction rate
        if (currentCount < this.minTransactionsPerSecond) {
          recommendations.push({
            type: 'optimize',
            reason: `Transaction count (${currentCount}) below minimum (${this.minTransactionsPerSecond})`
          });
        }
        
        return {
          currentCount,
          recommendations,
          metadata: {
            timestamp: Date.now()
          }
        };
      }
    }