Log
export class Log {
constructor(
public address: Address,
public topics: Array<Bytes>,
public data: Bytes,
public blockHash: Bytes,
public blockNumber: Bytes,
public transactionHash: Bytes,
public transactionIndex: BigInt,
public logIndex: BigInt,
public transactionLogIndex: BigInt,
public logType: string,
public removed: Wrapped<bool> | null,
) {}
}
Fields and Use Cases
address
- Description: The address of the smart contract that emitted the log.
- Use Case: Functions as a primary key for event filtering and enables foreign key relationships between Event entities and Contract entities. Commonly used in mapping files with
event.address.toHexString()
for entity lookups and joins.
topics
- Description: An array of 32-byte data fields containing indexed event parameters.
- Use Case: The first topic (topics[0]) contains the event signature hash (keccak256 of the event name and parameter types). Subsequent topics contain the indexed parameters in order of declaration.
data
- Description: The non-indexed data that was emitted along with the event.
- Use Case: Contains ABI-encoded parameters that weren’t marked as
indexed
in the event signature. Must be decoded usingethereum.decode()
or similar ABI decoding functions, with parameter types matching the event’s definition. The data is packed sequentially without padding between dynamic types.
blockHash
- Description: The hash of the block that includes the log.
- Use Case: Used to create relationships between event entities and block entities, and verify block inclusion in your subgraph.
blockNumber
- Description: The number of the block that includes the log.
- Use Case: Implements chronological indexing via
BigInt
comparisons and enables block-height-based queries. Critical for implementing pagination and historical data traversal in GraphQL endpoints.
transactionHash
- Description: The hash of the transaction that triggered the event.
- Use Case: Implements transaction entity relationships via
event.transaction.hash.toHexString()
and enables atomic grouping of event-driven entity updates within transaction boundaries.
transactionIndex
- Description: The index of the transaction within the block.
- Use Case: Helpful for maintaining correct event ordering when multiple transactions in a block emit the same event type.
logIndex
- Description: The index of the log within the block.
- Use Case: Used to create unique identifiers for event entities and maintain precise ordering of events within a block.
transactionLogIndex
- Description: The index of the log within the transaction.
- Use Case: Useful for ordering multiple events emitted by the same transaction when creating related entities.
logType
- Description: The type of the log, often used to specify the log’s origin or purpose.
- Use Case: Can be used to filter different types of events in your handlers, though rarely used in most subgraph implementations.
removed
- Description: Boolean value indicating if the event was removed due to a chain reorganization.
- Use Case: Implements chain reorganization handling logic via
if (event.removed) { ... }
checks. Critical for implementing entity deletion or state reversal during block reorganizations.
Important Notes
- The
topics
field allows efficient filtering of logs based on indexed parameters, can be used to match different event signatures to get more information about an event. - The
data
field provides non-indexed, additional information. This data can be converted to usable format by splitting it into bytes and converting it to desired format(address, bigInt, etc.).