Querying State

Querying the Blockchain State

It is necessary to query the blockchain state to get account balances, token balances, and other information.

Querying the State

All nodes contain the latest blockchain state. This means that you can query the state of the blockchain by connecting to an RPC node. There are three main ways to query the node:

  • RPC Endpoints
  • gRPC Endpoints
  • REST Endpoints
  • Websockets

Querying Historical State

When working with blockchain applications, querying historical state data is crucial for various types of applications. To query historical state data, you can use archive nodes and specify the block height at which you want to retrieve the state.

Example: To query the state at a specific block height, you can use the following approach:

Querying by block height with seid

seid query bank balances [address] --height <block_height>

• This command allows you to specify the block height and retrieve the state as it was at that particular point in time.

Pruning

Pruning is the process of removing old blockchain data that is no longer needed in order to save disk space and improve performance. Pruned nodes only retain a limited set of recent blockchain data, making them faster and less storage-intensive for RPC providers.

Purpose: Pruning helps reduce the storage requirements of blockchain nodes, making them more efficient and manageable.

Limitation: Pruned nodes do not retain the full history of the blockchain, so they cannot be used to query historical data beyond the pruning window.

Archive Nodes

Archive nodes, on the other hand, store the entire history of the blockchain from the genesis block to the latest block. This makes them essential for querying historical state data.

Purpose: Archive nodes retain the full blockchain history, allowing developers to query any past state by block height.

Use Cases: Archive nodes are crucial for tasks that require access to historical data, such as catching up indexers, conducting historical analysis, and verifying past transactions.

Querying by Block Height

Using Indexers for Historical Data

While archive nodes provide the raw historical data, indexers are essential for efficiently querying and analyzing this data. Indexers organize and optimize the data, making it easier to access and analyze.