getTransactionCount - Solana

The Web3 getTransactionCount JSON-RPC method retrieves the total number of transactions confirmed on the Solana network up to the latest block.

This method supports commitment parameters to determine data finality. Unlike Ethereum’s eth_getTransactionCount (which may trigger errors like AttributeError: 'Eth' object has no attribute 'gettransactioncount'), Solana’s implementation focuses on network-wide totals rather than per-account transactions.

Supported Networks

This method is accessible via Solana API endpoints:

  • Mainnet

  • Devnet

Parameters

  • commitment (string, optional): Specifies the confirmation level. Supported values:

    • finalized (default): Returns data from fully confirmed blocks.

    • confirmed: Uses the latest confirmed block.

    • processed: Not supported for this method.

  • minContextSlot (number, optional): The minimum slot at which the request can be evaluated. This ensures that data is only considered if the node has reached the specified slot.

Request

API Endpoint:

https://go.getblock.io/<ACCESS-TOKEN>/

getTransactionCount example Request (cURL):

curl --location "https://go.getblock.io/<ACCESS-TOKEN>/" -XPOST \
--header "Content-Type: application/json" \
--data '{
    "jsonrpc": "2.0",
    "method": "getTransactionCount",
    "params": [{"commitment": "finalized"}],
    "id": "getblock.io"
}'

Response

A successful response returns the total transaction count as an integer value.

Example Response:

{
    "id": "getblock.io",
    "jsonrpc": "2.0",
    "result": 60547116336
}

Response Parameters:

  • result: Total number of transactions confirmed up to the specified block.

Error Handling

Common getTransactionCount error scenarios include:

  • Using unsupported commitment levels like processed.

  • Invalid API key or incorrect endpoints.

  • Ethereum-specific errors (e.g., AttributeError: 'Eth' object has no attribute 'gettransactioncount' when using the Solana API).

Example Error Response:

{
    "jsonrpc": "2.0",
    "error": {
        "code": -32602,
        "message": "Unsupported commitment: processed"
    },
    "id": "getblock.io"
}

Use Cases

The getTransactionCount RPC method is ideal for:

  • Network dashboards displaying real-time transaction throughput;

  • Analytics platforms calculating TPS (transactions per second);

  • Developers monitoring blockchain health and activity;

  • Auditors verifying historical block data completeness.

Code getTransactionCount Example – Web3 Integration

const axios = require('axios');


const url = "https://go.getblock.io/<ACCESS-TOKEN>/"; 
const headers = { "Content-Type": "application/json" };


const payload = {
  jsonrpc: "2.0",
  method: "getTransactionCount",
  params: [{ commitment: "finalized" }],
  id: "getblock.io"
};


const fetchTransactionCount = async () => {
  try {
    const response = await axios.post(url, payload, { headers });

    if (response.status === 200 && response.data.result !== undefined) {
      const txCount = response.data.result;
      console.log("Total Transactions (Finalized):", txCount);
    } else {
      console.error("Unexpected response:", response.data);
    }
  } catch (error) {
    console.error("getTransactionCount error:", error.response?.data || error.message);
  }
};

fetchTransactionCount();

Integration with Web3

Integrate the getTransactionCount RPC Solana method into Web3 applications to track network scalability and performance metrics. By combining this method with block or transaction-specific queries, developers gain holistic insights into Solana’s value as a high-throughput blockchain.

Last updated