getLogs - SDK
Returns an array of logs that match the provided filter.
Don’t have an API key?
Start using this method in your app today. Get started for free
Description
Returns an array of logs that match the provided filter.
Parameters
filter
parameters
pending
(Not available on Ethereum) - A sample next block built by the client on top oflatest
and containing the set of transactions usually taken fromlocal
mempool. Intuitively, you can think of these as blocks that have not been mined yet.latest
- The most recent block in the canonical chain observed by the client, this block may be re-orged out of the canonical chain even under healthy/normal conditions.safe
- The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination. Intuitively, this block is “unlikely” to be re-orged. Only available on Ethereum Goerli.finalized
- The most recent crypto-economically secure block, that has been accepted by >2/3 of validators. Cannot be re-orged outside of manual intervention driven by community coordination. Intuitively, this block is very unlikely to be re-orged. Only available on Ethereum Goerli.earliest
- The lowest numbered block the client has available. Intuitively, you can think of this as the first block created.
Response
<Array<Log>>
response object parameters
Example Request and Response
Prerequisite: You will need to install the Alchemy SDK before making requests with it.
The commands for installing it using npm or yarn are given below:
Request
Here is an example of how to make a getLogs
request using the Alchemy SDK:
Response
Use Cases
Here are some possible use cases for the getLogs
method:
-
Event tracking:
getLogs
can be used to track specific events generated by smart contracts. This is useful for monitoring the state changes of a smart contract and taking action based on those changes. -
Analytics:
getLogs
can be used to analyze smart contract data and generate reports or visualizations. For example, you could usegetLogs
to analyze the frequency and volume of trades on a decentralized exchange. -
Debugging:
getLogs
can be used to debug smart contracts. If a smart contract is not behaving as expected, you can usegetLogs
to retrieve the events generated by the contract and identify where the issue is occurring.
Related Methods
Here are the methods related to getLogs
:
- getBlock -SDK: Returns the block from the network based on the provided block number or hash.