Skip to main content

getLogs

Efficiently access the blockchain logs that match your specified filters by using getLogs builder api method. getLogs serves as an access point to blockchain logs empowering developers with a valuable method for monitoring and analyzing events that may occur. This method offers a streamlined approach to access essential log details, including topics and data, making it indispensable for building decentralized applications (dApps) that interact with smart contracts

How to use getBlockReceipts method ?

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

info

Any combination of filters is accepted provided that:

  • if blockHash is present then neither fromBlock nor toBlock are allowed
  • if contractAddress is not present then the specified range of blocks cannot be greater than 2000 blocks; otherwise any block range is allowed

Parameters

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

FieldTypeDescription
fromBlockstringStarting block for logs retrieval (default latest)
toBlockstringEnding block for logs retrieval (default latest)
blockHashstringBlock hash for retrieving all logs within a single block (equivalent to fromBlock = toBlock)
contractAddressstringThe address of the log events sender contract
topic0stringTopic hash to retrieve logs with
topic1stringTopic hash to retrieve logs with
topic2stringTopic hash to retrieve logs with
topic3stringTopic hash to retrieve logs with
pageSizeintegerNumber 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.

info

Returns array of Log objects.

This API is paginated, response items are ordered by:

  • blockNumber
  • logIndex
FieldTypeDescription
countintegerThe number of the logs returned
nextPageKeystringKey to get the next page of results, if more results are available
logsarrayThe array of Log objects
blockHashstringThe hash of the block containing the logs
blockNumberintegerThe height of the block containing the logs
blockTimestampstringThe timestamp of the block containing the logs
transactionHashstringLog transaction hash
transactionIndexintegerLog transaction number
contractAddressstringThe address of the contract generating the log
topic0stringTopic to describe the log event, usually the first topic is the signature of the event name
topic1stringTopic to describe the log event
topic2stringTopic to describe the log event
topic3stringTopic to describe the log event
datastringAdditional data of the log event

Example Request and Result for getLogs

In this section, we provide an illustrative example of a request made to blockchain logs matching the given filters using the getLogs Builder API method. Additionally, we present the resulting response containing all the information about the returned blocks. Developers can use this as a reference for crafting their own requests and parsing the returned data when working with the getLogs method.

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 --location 'https://eth-mainnet.blastapi.io/<project-id>/builder/getLogs?blockHash=0x248aac16904eb52e25ff4a594acbea314a216d5fc0968facb0c10366503aaab2'

Result

{
"count": 198,
"logs": [
{
"blockHash": "0x248aac16904eb52e25ff4a594acbea314a216d5fc0968facb0c10366503aaab2",
"blockNumber": 18375873,
"blockTimestamp": "2023-10-18T07:51:59.000Z",
"transactionHash": "0x2c40ee001352cfb73a2047c0ec71f016a1bd02e7fa2ed35adeaee46ca0c7719e",
"transactionIndex": 0,
"logIndex": 0,
"contractAddress": "0xf482d79ae6e8725c199213fc909d6bc30df62815",
"topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"topic1": "0x000000000000000000000000e65f60ae20998b6cb2d2a6edb2e551843e7bb816",
"topic2": "0x000000000000000000000000c99d5ae8a7c36325294c2424928bd776ab63f8b7",
"data": "0x000000000000000000000000000000000000000000000000007e5196c1911e00"
},
{
"blockHash": "0x248aac16904eb52e25ff4a594acbea314a216d5fc0968facb0c10366503aaab2",
"blockNumber": 18375873,
"blockTimestamp": "2023-10-18T07:51:59.000Z",
"transactionHash": "0x9befb89d0180358d300180c24530d9a16382ef770ec3eddab641e878d71d64e6",
"transactionIndex": 1,
"logIndex": 1,
"contractAddress": "0x9b1f3625980e6acb153da8b06235923845ecca01",
"topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"topic1": "0x000000000000000000000000e29a909a294896c167adc29a05681ff987a1d145",
"topic2": "0x000000000000000000000000ca53029a981a807c78c7cde496c5b52ef4532445",
"data": "0x00000000000000000000000000000000000000000000000000000003866a1100"
},
```