Skip to main content

eth_getLogs

In this section, we will see how we can use Bitquery APIs as an alternative to the eth_getLogs JSON RPC method and return an array of Logs object matching the filter object(*optional).

The Logs object consist of the following data.

  • removed: (boolean) true when the log was removed, due to a chain reorganization. false if it's a valid log.
  • logIndex: Log index position in the block. Null when it is a pending log.
  • transactionIndex: Hexadecimal of the transactions index position from which the log created. Null when it is a pending log.
  • transactionHash: 32 bytes. Hash of the transactions from which this log was created. Null when it is a pending log.
  • blockHash: 32 bytes. Hash of the block where this log was in. Null when it is a pending log.
  • blockNumber: Block number where this log was in. Null when it is a pending log.
  • address: 20 bytes. Address from which this log originated.
  • data: Contains one or more 32-bytes non-indexed arguments of the log.
  • topics: An array of 0 to 4 indexed log arguments, each 32 bytes.

Get Latest Logs

This subscription API returns the stream of thelatest logs for the Ethereum Mainnet. Now note that there is currently no filter in place.


subscription {
EVM {
Events {
Block {
Hash
Number
}
Transaction {
Hash
Index
}
LogHeader {
Address
Data
Index
Removed
}
Topics {
Hash
}
}
}
}

Get Logs with Filteration

Now, just like the orignal eth_getLogs method, Bitquery APIs provides the option to filter out the Logs based on the following parameeters.

  • address: (optional) Contract address (20 bytes) or a list of addresses from which logs should originate.
  • topics: (optional) Array of 32 bytes DATA topics. Topics are order-dependent.
  • blockhash: (optional) Restricts the logs returned to the single block referenced in the 32-byte hash blockHash.

Get Logs Originated From an Address

This API returns the logs originated from a fixed address, which is 0x7d4a7be025652995364e0e232063abd9e8d65e6e in this case. Also, unlike the JSON RPC method you can fiter out the Logs from multiple addresses using this API.


{
EVM {
Events(
where: {LogHeader: {Address: {is: "0x7d4a7be025652995364e0e232063abd9e8d65e6e"}}}
limit: {count: 10}
) {
Block {
Hash
Number
}
Transaction {
Hash
Index
}
LogHeader {
Address
Data
Index
Removed
}
Topics {
Hash
}
}
}
}

Filter Logs on Topics

This query filters outs the Logs based on the topics. Also, this query filters out the Logs based on multiple Topics.


{
EVM {
Events(
where: {
Topics: {
includes: {
Hash: {
is:"e1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c"
}
}
}
}
) {
Block {
Hash
Number
}
Transaction {
Hash
Index
}
LogHeader {
Address
Data
Index
Removed
}
Topics {
Hash
}
}
}
}

Get Logs from a Block

Using this query, you can get the logs that belong to a particular block by using blockHash as a filter. Here 0xa0e1c15b905f4ed6f4e466b2693791ffc6be6ccd3a2a95d403585799ab5fecd9 is the parameter used for filteration.


{
EVM {
Events(
where: {
Block: {
Hash: {
is: "0xa0e1c15b905f4ed6f4e466b2693791ffc6be6ccd3a2a95d403585799ab5fecd9"
}
}
}
) {
Block {
Hash
Number
}
Transaction {
Hash
Index
}
LogHeader {
Address
Data
Index
Removed
}
Topics {
Hash
}
}
}
}