Skip to main content

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

FieldTypeDescription
fromBlockstring

Replace this with the desired starting block height for the query. If empty, all blocks prior to toBlock will be retrieved.

toBlockstring

Specify the desired end block height for the query. If left empty, all blocks ranging from fromBlock to the latest block will be retrieved.

pageSizenumber

Represents the maximum number of records to be retrieved in one page

pageKeystring

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

FieldTypeDescription
countnumberNumber of records returned in the current page
nextPageKeystring

Key used to get the next page of results. Must be set to the value of nextPageKey returned in the previous response

blocksobject<array>Returns the array of block objects in the given range
blockHashstringThe hash of the block
blockNumbernumberThe height of the block
blockTimestampstringThe timestamp of the block
parentBlockAddressstringThe hash that identifies the previous block in the chain
sequencerAddressstringThe sequencer address that constructed the block
stateRootstringThe state commitment after this block
statusstringThe status of the block
totalActualFeenumberThe gas fee the transaction paid
transactionCountnumberThe number of transactions in the specified block
eventCountnumberThe number of events
messageCountstringThe 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.

info

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

NameTypeDescription
fromBlockString501452
pageSizeString2
toBlockString501652
{
"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'