Transaction Receipt
export class TransactionReceipt {
constructor(
public transactionHash: Bytes,
public transactionIndex: BigInt,
public blockHash: Bytes,
public blockNumber: BigInt,
public cumulativeGasUsed: BigInt,
public gasUsed: BigInt,
public contractAddress: Address,
public logs: Array<Log>,
public status: BigInt,
public root: Bytes,
public logsBloom: Bytes,
) {}
}
Fields and Use Cases
transactionHash
- Description: The hash of the transaction associated with this receipt.
- Use Case: Used to create relationships between receipt entities and transaction entities in your subgraph schema.
transactionIndex
- Description: The index of the transaction within the block.
- Use Case: Useful for creating unique identifiers and maintaining transaction order when handling multiple events from the same block.
blockHash
- Description: The hash of the block that includes this transaction.
- Use Case: Used to link receipt entities with block entities and verify block inclusion in your subgraph.
blockNumber
- Description: The number of the block that includes this transaction.
- Use Case: Essential for temporal queries and filtering in your subgraph, often used in handler functions to track processing progress.
cumulativeGasUsed
- Description: The total amount of gas used in the block up to and including this transaction.
- Use Case: Useful for creating block-level analytics entities and tracking gas usage patterns in your subgraph.
gasUsed
- Description: The amount of gas consumed by this transaction alone.
- Use Case: Can be used to filter high-complexity transactions or create gas usage statistics entities in your subgraph.
contractAddress
- Description: The address of the smart contract deployed by this transaction, or
null
if no contract was created. - Use Case: Essential for tracking contract deployments and creating new contract entities in your subgraph schema.
logs
- Description: An array of event log objects generated during transaction execution. Each log contains the event data, topics (including the event signature), and metadata about where the event was emitted.
- Use Case: Primary source for event data in subgraph mappings. Used to:
- Create and update entities based on emitted events
- Track cross-contract interactions
- Extract indexed and non-indexed parameters from events
- Determine the exact sequence of events within a transaction
status
- Description: The success status of the transaction, represented as
1
for success or0
for failure. - Use Case: Can be used to filter failed transactions or track success rates in your subgraph entities.
root
- Description: The root of the state trie after the transaction execution.
- Use Case: Rarely used in modern subgraphs, but can be stored for historical analysis of pre-Byzantium blocks.
logsBloom
- Description: The bloom filter used by light clients to quickly retrieve logs related to the transaction.
- Use Case: Generally not used in subgraph development as The Graph has direct access to full log data.
Important Notes
logs
can be used to get more in-depth data about an event, for example in case of aERC721
transfer event, receipts can be used to find if it’s a trade event and the exchange data.- This can be done by matching the
topic0
of the receipt with the event signature.