Querying State
Querying Blockchain State
Querying the blockchain state to retrieve account balances, token balances, and other information is essential.
Querying State
All nodes contain the latest blockchain state. This means you can query the blockchain state by connecting to an RPC node. There are three primary methods to query a node:
RPC Endpoint
gRPC Endpoint
REST Endpoint
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 an archive node 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 method:
Querying with enid by block height
enid query bank balances [address] --height <block-height>
• This command allows you to specify a block height and retrieve the state at that specific point in time.
Pruning
Pruning is the process of removing old blockchain data that is no longer needed to save disk space and improve performance. Pruned nodes retain only a limited amount of recent blockchain data, making them faster and less storage-intensive for RPC providers.
• Purpose: Pruning helps reduce the storage requirements of a blockchain node, making it more efficient and easier to manage.
• Limitation: Pruned nodes do not retain the full blockchain history, so they cannot be used to query historical data beyond the pruning window.
Archive Nodes
On the other hand, archive nodes store the entire blockchain history from the genesis block to the latest block. This makes them essential for querying historical state data.
• Purpose: Archive nodes preserve the complete blockchain history, allowing developers to query any past state by block height.
• Use Cases: Archive nodes are critical for tasks requiring access to historical data, such as catching up indexers, conducting historical analysis, and verifying past transactions.
Using Indexers for Historical Data
While archive nodes provide raw historical data, indexers are vital for efficiently querying and analyzing this data. Indexers organize and optimize the data, making it more accessible and easier to analyze.
Last updated