Overview
ThegetBlock method retrieves detailed information about a specific block on the NEAR blockchain. You can query blocks by height, hash, or use predefined finality levels.
Method Signature
Parameters
Reference to the block you want to query. Can be:
{ blockHeight: number }- Query by block height{ blockHash: string }- Query by block hash'LatestOptimisticBlock'- Latest optimistic block'LatestNearFinalBlock'- Latest near-final block (default)'LatestFinalBlock'- Latest final block'EarliestAvailableBlock'- Earliest available block'GenesisBlock'- Genesis block
Transport policy for RPC request handling
AbortSignal to cancel the request
Return Value
The raw RPC response containing block information including:
- Block header (height, hash, timestamp)
- Block author
- Chunks information
- Gas and balance data
Error Types
ThesafeGetBlock method returns typed errors:
Client.GetBlock.Args.InvalidSchema- Invalid arguments providedClient.GetBlock.PreferredRpc.NotFound- Preferred RPC endpoint not foundClient.GetBlock.Timeout- Request timeoutClient.GetBlock.Aborted- Request abortedClient.GetBlock.Exhausted- All RPC endpoints exhaustedClient.GetBlock.Rpc.NotSynced- RPC node not syncedClient.GetBlock.Rpc.Block.NotFound- Block not foundClient.GetBlock.Internal- Internal error
Examples
Get Latest Block
Get Block by Height
Get Block by Hash
Get Final Block
Safe Usage with Error Handling
With Abort Signal
Source Code
- Implementation:
universal/src/client/methods/block/getBlock/getBlock.ts:20 - Type definitions:
universal/types/client/methods/block/getBlock.ts:21
Related
- Client - Creating a client instance
- Transport Policy - Configuring RPC transport