getBlockHeight
Learn getBlockHeight use cases, code examples, request parameters, response structure, and tips.
The getBlockHeight RPC method offers a quick way to query the current block height of a Solana node. Block height is defined as the total number of blocks processed since the genesis block (slot 0). This method is ideal for tracking the chain’s progression and aligning on-chain data with specific block intervals.
Common Use Cases
Monitoring Chain Progression Repeatedly call
getBlockHeightto track how fast the blockchain is advancing.Capturing a Snapshot of Chain Length Retrieve the current block height at a particular commitment level to reference the chain’s state at a specific point.
Cross-Referencing Data Use the block height as a timeline marker when correlating events, logs, or transactions across various tools and datasets.
Parameters
You can call getBlockHeight with or without a configuration object:
config(object, optional): Optional fields to refine the request:commitment(string): Defines the confirmation level of the block height being returned. Defaults tofinalized.finalized– Highest assurance of confirmation.confirmed– Voted on by a supermajority of validators.processed– Most recent block (may still change).
minContextSlot(number): Ensures the response is from a slot greater than or equal to this value. Useful for consistency and timeline alignment.
If no parameters are passed, the request defaults to the finalized commitment.
Response
The JSON-RPC result field will return:
blockHeight(number): An unsigned integer representing the height of the latest confirmed block.
Example: Fetching the Current Block Height
Here’s how to request the current block height from the CoinVera Mainnet RPC:
If you don’t need any custom configuration, you can also call it with no parameters:
Example Response
Developer Tips
Commitment Levels Matter The block height returned by
getBlockHeightdepends on the commitment level used:finalizedprovides the most stable and reliable block height.processedoffers the most up-to-date value, but it may not be confirmed and could change.
Use
minContextSlotfor Consistency When tracking specific slots, settingminContextSlotensures that the block height returned is based on a state at or after that slot—ideal for maintaining temporal consistency in your application logic.Block Height ≠ Slot Number It's important to distinguish between block height and slot number:
A slot is a time window where a validator may produce a block.
Skipped slots occur when no block is produced.
Block height only increments when a block is actually produced.
Lightweight Chain Health Monitoring Although basic,
getBlockHeightis a quick and effective method to track chain progression or include in synchronization and health checks for validators, dApps, or backend systems.
Last updated