Links

getBlocks

Get all blocks in a given range
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 will be retrieved.
toBlock
string
Specify the desired end block height for the query. If left empty, all blocks ranging from fromBlock to the latest block will be retrieved.
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!
get
https://starknet-mainnet.blastapi.io/<project-id>/builder/getBlocks?
Returns all te blocks in a given range fromBlock to toBlock
Parameters
Query
fromBlock
501452
toBlock
501652
pageSize
2
Responses
200: OK
Expand for a detailed response example

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'