Class BlockDataExtensions
Extension methods for querying block data from the mirror node.
Inherited Members
Namespace: Hiero.Mirror
Assembly: Hiero.dll
Syntax
public static class BlockDataExtensions
Methods
| Edit this page View SourceGetBlockAsync(MirrorRestClient, long, CancellationToken)
Retrieves a single block by number from
/api/v1/blocks/{blockNumber}.
Declaration
public static Task<BlockData?> GetBlockAsync(this MirrorRestClient client, long blockNumber, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| MirrorRestClient | client | Mirror Rest Client to use for the request. |
| long | blockNumber | Block Number |
| CancellationToken | cancellationToken | Optional token that cancels the request. |
Returns
| Type | Description |
|---|---|
| Task<BlockData> | Information for the block, or null if not found. |
GetBlockAsync(MirrorRestClient, ReadOnlyMemory<byte>, CancellationToken)
Retrieves a single block by hash from
/api/v1/blocks/{blockHash}.
Declaration
public static Task<BlockData?> GetBlockAsync(this MirrorRestClient client, ReadOnlyMemory<byte> blockhash, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| MirrorRestClient | client | Mirror Rest Client to use for the request. |
| ReadOnlyMemory<byte> | blockhash | The block hash bytes — accepts the 48-byte Hedera SHA-384 record-file hash returned by the mirror, or a 32-byte EVM block hash for callers that have one. |
| CancellationToken | cancellationToken | Optional token that cancels the request. |
Returns
| Type | Description |
|---|---|
| Task<BlockData> | Information for the block, or null if not found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
GetBlocksAsync(MirrorRestClient, params IMirrorQueryParameter[])
Enumerates blocks from the chain. Default ordering is newest-first; pass Ascending to reverse. Pair with BlockNumberFilter or TimestampFilter to bound a range.
Declaration
public static IAsyncEnumerable<BlockData> GetBlocksAsync(this MirrorRestClient client, params IMirrorQueryParameter[] filters)
Parameters
| Type | Name | Description |
|---|---|---|
| MirrorRestClient | client | Mirror Rest Client to use for the request. |
| IMirrorQueryParameter[] | filters | Additional query filters. The endpoint supports BlockNumberFilter, TimestampFilter, PageLimit, and OrderBy. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<BlockData> | An async enumerable of block records. |
GetBlocksAsync(MirrorRestClient, CancellationToken, params IMirrorQueryParameter[])
Enumerates blocks from the chain. Default ordering is newest-first; pass Ascending to reverse. Pair with BlockNumberFilter or TimestampFilter to bound a range.
Declaration
public static IAsyncEnumerable<BlockData> GetBlocksAsync(this MirrorRestClient client, CancellationToken cancellationToken, params IMirrorQueryParameter[] filters)
Parameters
| Type | Name | Description |
|---|---|---|
| MirrorRestClient | client | Mirror Rest Client to use for the request. |
| CancellationToken | cancellationToken | Token that cancels the enumeration, including a page request in
flight. |
| IMirrorQueryParameter[] | filters | Additional query filters. The endpoint supports BlockNumberFilter, TimestampFilter, PageLimit, and OrderBy. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<BlockData> | An async enumerable of block records. |
GetLatestBlockAsync(MirrorRestClient, CancellationToken)
Retrieves the most recent block observed by the mirror node via
/api/v1/blocks?limit=1&order=desc (there is no
dedicated "latest block" endpoint).
Declaration
public static Task<BlockData?> GetLatestBlockAsync(this MirrorRestClient client, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| MirrorRestClient | client | Mirror Rest Client to use for the request. |
| CancellationToken | cancellationToken | Optional token that cancels the request. |
Returns
| Type | Description |
|---|---|
| Task<BlockData> | Block information for the latest known block, or null if the mirror node returns no blocks. Request errors are thrown as MirrorException, not reported as null. |
GetLatestBlockBeforeConsensusAsync(MirrorRestClient, ConsensusTimeStamp, CancellationToken)
Retrieves the latest known block at or before the given consensus timestamp.
Declaration
public static Task<BlockData?> GetLatestBlockBeforeConsensusAsync(this MirrorRestClient client, ConsensusTimeStamp consensus, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| MirrorRestClient | client | Mirror Rest Client to use for the request. |
| ConsensusTimeStamp | consensus | The consensus timestamp |
| CancellationToken | cancellationToken | Optional token that cancels the request. |
Returns
| Type | Description |
|---|---|
| Task<BlockData> | Block info for the latest block at or before the given timestamp, or null if there is no such block. |