getblocks
description: Get all blocks in a given range
getBlocks
Efficiently retrieves the contents of blocks within the specified range. This versatile API offers pagination for seamless data retrieval, and it ensures that response items are arranged in descending order according to their block number for your convenience.
How to use getBlocks method ?
Below, you'll find an extensive guide on effectively leveraging the capabilities of the getBlocks method.
Parameters
Field | Type | Description |
---|---|---|
fromBlock | string | Replace this with the desired starting block height for the query. If
empty, all blocks prior to |
toBlock | string | Specify the desired end block height for the query. If left empty, all
blocks ranging from |
pageSize | number | Represents the maximum number of records to be retrieved in one page |
pageKey | string | Represents the key used to get the next page of results. Must be set to the value of nextPageKey returned in the previous response |
Results
Field | Type | Description |
---|---|---|
count | number | Number of records returned in the current page |
nextPageKey | string | Key used to get the next page of results. Must be set to the value of nextPageKey returned in the previous response |
blocks | object<array> | Returns the array of block objects in the given range |
blockHash | string | The hash of the block |
blockNumber | number | The height of the block |
blockTimestamp | string | The timestamp of the block |
parentBlockAddress | string | The hash that identifies the previous block in the chain |
sequencerAddress | string | The sequencer address that constructed the block |
stateRoot | string | The state commitment after this block |
status | string | The status of the block |
totalActualFee | number | The gas fee the transaction paid |
transactionCount | number | The number of transactions in the specified block |
eventCount | number | The number of events |
messageCount | string | The number of messages |
Example Request and Result for getBlocks
In this section, we provide an illustrative example of a request made to retrieve block contents using the getBlocks
Builder API method. Additionally, we present the resulting response containing information about the specified block. This example demonstrates how to interact with the API to obtain details about a specific block, including its hash, block number, timestamp, and various other attributes. Developers can use this as a reference for crafting their own requests and parsing the returned data when working with the getBlocks
endpoint.
The example in this section uses a non-existing project id.
Make sure you replace it with your Starknet endpoint when issuing the Builder API calls.
Don't have a project id? Here's a straightforward guide on how to obtain one!
Returns all te blocks in a given range fromBlock to toBlock
GET
https://starknet-mainnet.blastapi.io/<project-id>/builder/getBlocks?
Query Parameters
Name | Type | Description |
---|---|---|
fromBlock | String | 501452 |
pageSize | String | 2 |
toBlock | String | 501652 |
- 200: OK Expand for a detailed response example
{
"count": 2,
"nextPageKey": "ZjgyYzE1ZDFlNDU3OjE3MDQ4OTIxMzU6NTAxNjUx",
"blocks": [
{
"blockHash": "0x05623571ff137d26b2dd9fd925f4e02cd88ec26bd45ac4e6f7ae738d4c055ba5",
"blockNumber": 501652,
"blockTimestamp": "2024-01-10T12:21:47.000Z",
"parentBlockHash": "0x066261ca033ac76af17c499101a6b22b794f6c8bd5308bb2b20814d2599c0ccb",
"sequencerAddress": "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
"stateRoot": "0x0099360f339dd48fa77bdf66b2cbfb375a7de9de872798f7374e98e4e2639896",
"status": "ACCEPTED_ON_L2",
"totalActualFee": "28896563259679808",
"transactionCount": 118,
"eventCount": 794,
"messageCount": 0
},
{
"blockHash": "0x066261ca033ac76af17c499101a6b22b794f6c8bd5308bb2b20814d2599c0ccb",
"blockNumber": 501651,
"blockTimestamp": "2024-01-10T12:20:25.000Z",
"parentBlockHash": "0x03d3d7056db7f43acfb83c3720846241af80425549e357520a18137a844077be",
"sequencerAddress": "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
"stateRoot": "0x02f69d27beb9875a1e5ed15c155bb5e629240457a4da64f2f4004ffbc678e7a7",
"status": "ACCEPTED_ON_L2",
"totalActualFee": "28369981818598784",
"transactionCount": 119,
"eventCount": 808,
"messageCount": 0
}
]
}
Curl request example
curl -X GET https://starknet-mainnet.blastapi.io/<project-id>/builder/getBlocks?fromBlock=501452&toBlock=501652&pageSize=2 -H 'Content-Type: application/json'