getMessages

Get all messages in a given block range

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

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.

FieldTypeDescription

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!

Get all messages in a given block range

GET https://starknet-mainnet.blastapi.io/<project-id>/builder/getMessages?

Query Parameters

NameTypeDescription

fromBlock

String

313696

toBlock

String

313796

{
"count":100
"nextPageKey":"MjMyZDk5ZjQwOTVlOjE3MDQ5MDMxODU6MzEzNzYwOjI"
"messages":[
0:{
"blockHash":"0x054010f1e0b1d90122685fd752a2cb2e845b1272e850bbcc…"
"blockNumber":313796
"blockTimestamp":"2023-10-11T13:39:55.000Z"
"transactionHash":"0x0465df82d9bf419cd2e7adeaa5ac727093d0ef9aae680a10…"
"transactionIndex":50
"messageIndex":5
"fromAddress":"0xae0ee0a63a2ce6baeeffe56e7714fb4efe48d419"
"toAddress":"0x073314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4…"
"direction":"L1_TO_L2"
"payload":[]
"entryPointSelector":"0x02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff…"
}
...

Curl request example

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

Last updated