Parameters
Configuration object containing:Commitment level (processed, confirmed, finalized)
Response
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
- Returns the current transaction count from the ledger
- The count includes all transactions processed by the node
- The response is immediate as it reads from the current state
- The count can change with new transactions
- The count may vary between nodes due to network propagation
Best Practices
- Use appropriate commitment level based on your needs
- Cache results when appropriate to reduce RPC load
- Monitor for changes in transaction count
- Consider using websocket subscription for real-time updates
- Handle network errors and retry when appropriate
Common Errors
Code | Message | Solution |
---|
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32602 | Invalid params | Check configuration parameters |
Use Cases
-
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
}
};
}
}
-
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;
}
}
-
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()
}
};
}
}