Skip to main content

getMessages

Contracts L2 can participate in asynchronous interactions with contracts on L1 through the L2→L1 messaging protocol. Similarly, contracts on L1 can engage in asynchronous interactions with contracts on L2 via the L1→L2 messaging protocol. The getMessages Builder API method enables you to retrieve all messages within a specified block range. This API is paginated, with response items ordered in descending order by blockNumber and messageIndex for your convenience.

How to use getMessages method ?

Below, you'll find an in-depth guide that provides a comprehensive explanation of how to utilize the getMessages Builder API method effectively using Blast.

Parameters

Below, you can find the query parameters accepted by the method.

FieldTypeDescription
fromBlockstringStarting block of the query
toBlockstringEnding block for the query
pageSizenumberNumber of records to be retrieved on one page
pageKeystringKey used to get the next page of results. Must be set to the value of nextPageKey returned in the previous response

Returns

Discover an insightful explanation of the returned parameters here, offering a deep understanding of their significance and implications.

FieldTypeDescription
countnumberNumber of records returned in the current page
nextPageKeystringKey to get the next page of results, if more results are available
messagesarray<string>The array of message objects
blockHashstringThe block hash that the message is in
blockNumbernumberThe block number that the message is in
blockTimestampstringThe timestamp in seconds for when the message was emitted
transactionHashstringThe transaction hash that the message is in
transactionIndexnumberThe index of the transaction
messageIndexnumberThe message index
fromAddressstringThe address of the contract emitting the message
toAddressstringThe contract address that received the message
toAddressstringThe direction of the message between L1 and L2 (L1_TO_L2, L2_TO_L1)
payloadarrayThe contents of the message
entryPointSelectorarrayThe function selector to call on L1 or L2

Example Request and Result for getMessages

In this section, you will find an example request and its corresponding result for the getMessages API method. This specific request demonstrates how to retrieve all messages from a specified fromAddress to a designated toAddress range, providing you with a practical illustration of the API's functionality.

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!

Curl request example

curl -X GET https://starknet-mainnet.blastapi.io/<project-id>/builder/getMessages?fromBlock=313696&toBlock=313796 -H 'Content-Type: application/json'