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.
Field | Type | Description |
---|---|---|
fromBlock | string | Starting block of the query |
toBlock | string | Ending block for the query |
pageSize | number | Number of records to be retrieved on one page |
pageKey | string | Key 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.
Field | Type | Description |
---|---|---|
count | number | Number of records returned in the current page |
nextPageKey | string | Key to get the next page of results, if more results are available |
messages | array<string> | The array of message objects |
blockHash | string | The block hash that the message is in |
blockNumber | number | The block number that the message is in |
blockTimestamp | string | The timestamp in seconds for when the message was emitted |
transactionHash | string | The transaction hash that the message is in |
transactionIndex | number | The index of the transaction |
messageIndex | number | The message index |
fromAddress | string | The address of the contract emitting the message |
toAddress | string | The contract address that received the message |
toAddress | string | The direction of the message between L1 and L2 (L1_TO_L2, L2_TO_L1) |
payload | array | The contents of the message |
entryPointSelector | array | The 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.
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'